
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>logback中文网|第七章：Filters</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="logback中文网包含了logback中文文档，最新资讯，应用案例等。logback 继承自 log4j，它建立在有十年工业经验的日志系统之上。它比其它所有的日志系统更快并且更小，包含了许多独特并且有用的特性。"><meta name="keywords" content="logback中文文档, logback api文档, logback log4j,springboot logback,logback日志类型">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="08第八章MDC.html" />
    
    
    <link rel="prev" href="06第六章Layouts.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="./">
            
                <a href="./">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="01第一章logback介绍.html">
            
                <a href="01第一章logback介绍.html">
            
                    
                    第一章：logback 介绍
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="02第二章架构.html">
            
                <a href="02第二章架构.html">
            
                    
                    第二章：架构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="03第三章logback的配置.html">
            
                <a href="03第三章logback的配置.html">
            
                    
                    第三章：logback 的配置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="04第四章Appenders.html">
            
                <a href="04第四章Appenders.html">
            
                    
                    第四章：Appenders
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="05第五章Encoder.html">
            
                <a href="05第五章Encoder.html">
            
                    
                    第五章：Encoder
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="06第六章Layouts.html">
            
                <a href="06第六章Layouts.html">
            
                    
                    第六章：Layouts
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.8" data-path="07第七章Filters.html">
            
                <a href="07第七章Filters.html">
            
                    
                    第七章：Filters
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="08第八章MDC.html">
            
                <a href="08第八章MDC.html">
            
                    
                    第八章：MDC
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="09第九章日志隔离.html">
            
                <a href="09第九章日志隔离.html">
            
                    
                    第九章：日志隔离
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="10第十章JMX配置器.html">
            
                <a href="10第十章JMX配置器.html">
            
                    
                    第十章：JMX 配置器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="11第十一章Joran.html">
            
                <a href="11第十一章Joran.html">
            
                    
                    第十一章：Joran
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="12第十二章Groovy配置.html">
            
                <a href="12第十二章Groovy配置.html">
            
                    
                    第十二章：Groovy 配置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14" data-path="13第十三章从log4j迁移.html">
            
                <a href="13第十三章从log4j迁移.html">
            
                    
                    第十三章：从 log4j 迁移
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15" data-path="14第十四章Receivers.html">
            
                <a href="14第十四章Receivers.html">
            
                    
                    第十四章：Receivers
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.16" data-path="15第十五章使用SSL.html">
            
                <a href="15第十五章使用SSL.html">
            
                    
                    第十五章：使用 SSL
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="." >第七章：Filters</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <p>&#x5728;&#x4E4B;&#x524D;&#x7684;&#x7AE0;&#x8282;&#x4E2D;&#x4ECB;&#x7ECD;&#x7684;<a href="https://github.com/Volong/logback-chinese-manual/blob/master/02%E7%AC%AC%E4%BA%8C%E7%AB%A0%EF%BC%9A%E6%9E%B6%E6%9E%84.md#%E6%96%B9%E6%B3%95%E6%89%93%E5%8D%B0%E4%BB%A5%E5%8F%8A%E5%9F%BA%E6%9C%AC%E9%80%89%E6%8B%A9%E8%A7%84%E5%88%99" target="_blank">&#x65B9;&#x6CD5;&#x6253;&#x5370;&#x4EE5;&#x53CA;&#x57FA;&#x672C;&#x9009;&#x62E9;&#x89C4;&#x5219;</a>&#x662F; logback-classic &#x7684;&#x6838;&#x5FC3;&#x3002;&#x5728;&#x8FD9;&#x7AE0;&#x4E2D;&#xFF0C;&#x5C06;&#x4ECB;&#x7ECD;&#x5176;&#x5B83;&#x7684;&#x8FC7;&#x6EE4;&#x65B9;&#x6CD5;&#x3002;</p>
<p>logback &#x8FC7;&#x6EE4;&#x5668;&#x57FA;&#x4E8E;&#x4E09;&#x5143;&#x903B;&#x8F91;&#xFF0C;&#x5141;&#x8BB8;&#x5B83;&#x4EEC;&#x7EC4;&#x88C5;&#x6216;&#x8005;&#x94FE;&#x63A5;&#x5728;&#x4E00;&#x8D77;&#x7EC4;&#x6210;&#x4E00;&#x4E2A;&#x4EFB;&#x610F;&#x590D;&#x6742;&#x7684;&#x8FC7;&#x6EE4;&#x7B56;&#x7565;&#x3002;&#x5B83;&#x4EEC;&#x5728;&#x5F88;&#x5927;&#x7A0B;&#x5EA6;&#x4E0A;&#x53D7;&#x5230; Linux iptables &#x7684;&#x542F;&#x53D1;&#x3002;</p>
<h2 id="&#x5728;-logback-classic-&#x4E2D;">&#x5728; logback-classic &#x4E2D;</h2>
<p>&#x5728; logback-classic &#x4E2D;&#xFF0C;&#x6709;&#x4E24;&#x79CD;&#x7C7B;&#x578B;&#x7684;&#x8FC7;&#x6EE4;&#x5668;&#xFF0C;regular &#x8FC7;&#x6EE4;&#x5668;&#x4EE5;&#x53CA; turbo &#x8FC7;&#x6EE4;&#x5668;&#x3002;</p>
<h3 id="regular-&#x8FC7;&#x6EE4;&#x5668;">Regular &#x8FC7;&#x6EE4;&#x5668;</h3>
<p>reqular &#x8FC7;&#x6EE4;&#x5668;&#x7EE7;&#x627F;&#x81EA; <a href="https://logback.qos.ch/xref/ch/qos/logback/core/filter/Filter.html" target="_blank"><code>Filter</code></a> &#x8FD9;&#x4E2A;&#x62BD;&#x8C61;&#x7C7B;&#x3002;&#x672C;&#x8D28;&#x4E0A;&#x5B83;&#x7531;&#x4E00;&#x4E2A;&#x5355;&#x4E00;&#x7684; <code>decide()</code> &#x65B9;&#x6CD5;&#x7EC4;&#x6210;&#xFF0C;&#x63A5;&#x6536;&#x4E00;&#x4E2A; <code>ILoggingEvent</code> &#x5B9E;&#x4F8B;&#x4F5C;&#x4E3A;&#x53C2;&#x6570;&#x3002;</p>
<p>&#x8FC7;&#x6EE4;&#x5668;&#x901A;&#x8FC7;&#x4E00;&#x4E2A;&#x6709;&#x5E8F;&#x5217;&#x8868;&#x8FDB;&#x884C;&#x7BA1;&#x7406;&#xFF0C;&#x5E76;&#x4E14;&#x57FA;&#x4E8E;&#x4E09;&#x5143;&#x903B;&#x8F91;&#x3002;&#x6BCF;&#x4E2A;&#x8FC7;&#x6EE4;&#x5668;&#x7684; <code>decide(ILoggingEvent event)</code> &#x88AB;&#x4F9D;&#x6B21;&#x8C03;&#x7528;&#x3002;&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;&#x8FD4;&#x56DE; <a href="https://logback.qos.ch/xref/ch/qos/logback/core/spi/FilterReply.html" target="_blank"><code>FilterReply</code></a> &#x679A;&#x4E3E;&#x503C;&#x4E2D;&#x7684;&#x4E00;&#x4E2A;&#xFF0C; <code>DENY</code>, <code>NEUTRAL</code> &#x6216;&#x8005; <code>ACCEPT</code>&#x3002;&#x5982;&#x679C; <code>decide()</code> &#x65B9;&#x6CD5;&#x8FD4;&#x56DE; <code>DENY</code>&#xFF0C;&#x90A3;&#x4E48;&#x65E5;&#x5FD7;&#x4E8B;&#x4EF6;&#x4F1A;&#x88AB;&#x4E22;&#x5F03;&#x6389;&#xFF0C;&#x5E76;&#x4E14;&#x4E0D;&#x4F1A;&#x8003;&#x8651;&#x540E;&#x7EED;&#x7684;&#x8FC7;&#x6EE4;&#x5668;&#x3002;&#x5982;&#x679C;&#x8FD4;&#x56DE;&#x7684;&#x503C;&#x662F; <code>NEUTRAL</code>&#xFF0C;&#x90A3;&#x4E48;&#x624D;&#x4F1A;&#x8003;&#x8651;&#x540E;&#x7EED;&#x7684;&#x8FC7;&#x6EE4;&#x5668;&#x3002;&#x5982;&#x679C;&#x6CA1;&#x6709;&#x5176;&#x5B83;&#x7684;&#x8FC7;&#x6EE4;&#x5668;&#x4E86;&#xFF0C;&#x90A3;&#x4E48;&#x65E5;&#x5FD7;&#x4E8B;&#x4EF6;&#x4F1A;&#x88AB;&#x6B63;&#x5E38;&#x5904;&#x7406;&#x3002;&#x5982;&#x679C;&#x8FD4;&#x56DE;&#x503C;&#x662F; <code>ACCEPT</code>&#xFF0C;&#x90A3;&#x4E48;&#x4F1A;&#x8DF3;&#x8FC7;&#x5269;&#x4E0B;&#x7684;&#x8FC7;&#x6EE4;&#x5668;&#x800C;&#x76F4;&#x63A5;&#x88AB;&#x5904;&#x7406;&#x3002;</p>
<p>&#x5728; logback-classic &#x4E2D;&#xFF0C;&#x8FC7;&#x6EE4;&#x5668;&#x53EF;&#x4EE5;&#x88AB;&#x76F4;&#x63A5;&#x6DFB;&#x52A0;&#x5230; <code>Appender</code> &#x5B9E;&#x4F8B;&#x4E0A;&#x3002;&#x901A;&#x8FC7;&#x5C06;&#x4E00;&#x4E2A;&#x6216;&#x8005;&#x591A;&#x4E2A;&#x8FC7;&#x6EE4;&#x5668;&#x6DFB;&#x52A0;&#x5230; appender &#x4E0A;&#xFF0C;&#x4F60;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x4EFB;&#x610F;&#x6807;&#x51C6;&#x6765;&#x8FC7;&#x6EE4;&#x65E5;&#x5FD7;&#x4E8B;&#x4EF6;&#x3002;&#x4F8B;&#x5982;&#xFF0C;&#x65E5;&#x5FD7;&#x6D88;&#x606F;&#x7684;&#x5185;&#x5BB9;&#xFF0C;MDC &#x7684;&#x5185;&#x5BB9;&#xFF0C;&#x65F6;&#x95F4;&#xFF0C;&#x6216;&#x8005;&#x65E5;&#x5FD7;&#x4E8B;&#x4EF6;&#x7684;&#x5176;&#x5B83;&#x90E8;&#x5206;&#x3002;</p>
<h3 id="&#x5B9E;&#x73B0;&#x4F60;&#x81EA;&#x5DF1;&#x7684;&#x8FC7;&#x6EE4;&#x5668;">&#x5B9E;&#x73B0;&#x4F60;&#x81EA;&#x5DF1;&#x7684;&#x8FC7;&#x6EE4;&#x5668;</h3>
<p>&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x81EA;&#x5DF1;&#x7684;&#x8FC7;&#x6EE4;&#x5668;&#x975E;&#x5E38;&#x7684;&#x7B80;&#x5355;&#x3002;&#x53EA;&#x9700;&#x8981;&#x7EE7;&#x627F; <code>Filter</code> &#x5E76;&#x4E14;&#x5B9E;&#x73B0; <code>decide()</code> &#x65B9;&#x6CD5;&#x5C31;&#x53EF;&#x4EE5;&#x4E86;&#x3002;</p>
<p>&#x5982;&#x4E0B;&#x6240;&#x793A;&#x7684; SampleFilter &#x5C31;&#x662F;&#x4E00;&#x4E2A;&#x7B80;&#x5355;&#x7684;&#x4F8B;&#x5B50;&#x3002;&#x5982;&#x679C;&#x65E5;&#x5FD7;&#x4E8B;&#x4EF6;&#x5305;&#x542B;&#x5B57;&#x7B26; &quot;sample&quot;&#xFF0C; <code>decide</code> &#x65B9;&#x6CD5;&#x8FD4;&#x56DE; ACCEPT&#x3002;&#x5BF9;&#x4E8E;&#x5176;&#x4ED6;&#x7684;&#x65E5;&#x5FD7;&#x4E8B;&#x4EF6;&#xFF0C;&#x5219;&#x8FD4;&#x56DE; NEUTRAL&#x3002;</p>
<p>&#x4E0B;&#x9762;&#x662F;&#x5173;&#x4E8E;&#x5C06; <code>SampleFilter</code> &#x6DFB;&#x52A0;&#x5230; <code>ConsoleAppender</code> &#x4E0A;&#x7684;&#x914D;&#x7F6E;&#x793A;&#x4F8B;&#xFF1A;</p>
<blockquote>
<p>  Example: <em>SampleFilterConfig.xml</em></p>
</blockquote>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">configuration</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">appender</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;STDOUT&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;ch.qos.logback.core.ConsoleAppender&quot;</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">filter</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;chapters.filters.SampleFilter&quot;</span> /&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">encoder</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">pattern</span>&gt;</span>
        %-4relative [%thread] %-5level %logger - %msg%n
      <span class="hljs-tag">&lt;/<span class="hljs-name">pattern</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">encoder</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">appender</span>&gt;</span>

  <span class="hljs-tag">&lt;<span class="hljs-name">root</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">appender-ref</span> <span class="hljs-attr">ref</span>=<span class="hljs-string">&quot;STDOUT&quot;</span> /&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">root</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">configuration</span>&gt;</span>
</code></pre>
<p>&#x5728; logback &#x914D;&#x7F6E;&#x6846;&#x67B6; Joran &#x7684;&#x5E2E;&#x52A9;&#x4E0B;&#xFF0C;&#x4E3A;&#x8FC7;&#x6EE4;&#x5668;&#x6307;&#x5B9A;&#x5C5E;&#x6027;&#x6216;&#x8005;&#x5B50;&#x7EC4;&#x4EF6;&#x4E5F;&#x53D8;&#x5F97;&#x66F4;&#x52A0;&#x7684;&#x7B80;&#x5355;&#x3002;&#x5728;&#x8FC7;&#x6EE4;&#x5668;&#x7C7B;&#x4E2D;&#x6DFB;&#x52A0;&#x76F8;&#x5E94;&#x7684; set &#x65B9;&#x6CD5;&#xFF0C;&#x901A;&#x8FC7; <code>&lt;filter&gt;</code> &#x5143;&#x7D20;&#x5D4C;&#x5957;&#x4E00;&#x4E2A;&#x4EE5;&#x5C5E;&#x6027;&#x547D;&#x540D;&#x7684; xml &#x5143;&#x7D20;&#x4E2D;&#x6307;&#x5B9A;&#x5C5E;&#x6027;&#x7684;&#x503C;&#x3002;</p>
<p>&#x901A;&#x5E38;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x8FC7;&#x6EE4;&#x5668;&#x7684;&#x903B;&#x8F91;&#x7531;&#x4E24;&#x4E2A;&#x6B63;&#x4EA4;&#x7684;&#x90E8;&#x5206;&#x7EC4;&#x6210;&#xFF0C;match/mismatch &#x7684;&#x68C0;&#x9A8C;&#x4EE5;&#x53CA;&#x57FA;&#x4E8E; match/mismatch &#x7684;&#x8FD4;&#x56DE;&#x503C;&#x3002;&#x4F8B;&#x5982;&#xFF0C;&#x5BF9;&#x4E8E;&#x7ED9;&#x5B9A;&#x7684;&#x68C0;&#x9A8C;&#xFF0C;&#x6D88;&#x606F;&#x7B49;&#x4E8E; &quot;foobar&quot;&#xFF0C;&#x4E00;&#x4E2A;&#x8FC7;&#x6EE4;&#x5668;&#x5728; match &#x7684;&#x60C5;&#x51B5;&#x4E0B;&#x8FD4;&#x56DE; ACCEPT&#xFF0C;&#x5728; mismatch &#x7684;&#x60C5;&#x51B5;&#x4E0B;&#x8FD4;&#x56DE; NEUTRAL&#x3002;&#x53E6;&#x4E00;&#x4E2A;&#x8FC7;&#x6EE4;&#x53EF;&#x80FD;&#x5728; match &#x7684;&#x60C5;&#x51B5;&#x4E0B;&#x8FD4;&#x56DE; NEUTRAL&#xFF0C;&#x5728; mismatch &#x7684;&#x60C5;&#x51B5;&#x4E0B;&#x8FD4;&#x56DE; DENY&#x3002;</p>
<p>&#x6CE8;&#x610F;&#x8FD9;&#x79CD;&#x6B63;&#x4EA4;&#xFF0C;logback &#x9644;&#x5E26;&#x4E86;&#x4E00;&#x4E2A; <a href="https://logback.qos.ch/xref/ch/qos/logback/core/filter/AbstractMatcherFilter.html" target="_blank"><code>AbstractMatcherFilter</code></a> &#x7C7B;&#xFF0C;&#x63D0;&#x4F9B;&#x4E86;&#x4E00;&#x4E2A;&#x6709;&#x7528;&#x7684;&#x9AA8;&#x67B6;&#x7528;&#x6765;&#x6307;&#x5B9A;&#x5728; match &#x4E0E; mismatch &#x60C5;&#x51B5;&#x4E0B;&#x7684;&#x8FD4;&#x56DE;&#x503C;&#xFF0C;&#x8FD9;&#x4E24;&#x4E2A;&#x5C5E;&#x6027;&#x540D;&#x5206;&#x522B;&#x53EB;&#x505A; <em>OnMatch</em> &#x4E0E; <em>OnMismatch</em>&#x3002;logback &#x4E2D;&#x5927;&#x90E8;&#x5206;&#x7684; regular &#x8FC7;&#x6EE4;&#x5668;&#x90FD;&#x6E90;&#x4E8E; <code>AbstractMatcherFilter</code>&#x3002;</p>
<h3 id="levelfilter">LevelFilter</h3>
<p><a href="https://logback.qos.ch/xref/ch/qos/logback/classic/filter/LevelFilter.html" target="_blank"><code>LevelFilter</code></a> &#x57FA;&#x4E8E;&#x7EA7;&#x522B;&#x6765;&#x8FC7;&#x6EE4;&#x65E5;&#x5FD7;&#x4E8B;&#x4EF6;&#x3002;&#x5982;&#x679C;&#x4E8B;&#x4EF6;&#x7684;&#x7EA7;&#x522B;&#x4E0E;&#x914D;&#x7F6E;&#x7684;&#x7EA7;&#x522B;&#x76F8;&#x7B49;&#xFF0C;&#x8FC7;&#x6EE4;&#x5668;&#x4F1A;&#x6839;&#x636E;&#x914D;&#x7F6E;&#x7684; <code>onMatch</code> &#x4E0E; <code>onMismatch</code> &#x5C5E;&#x6027;&#xFF0C;&#x63A5;&#x53D7;&#x6216;&#x8005;&#x62D2;&#x7EDD;&#x4E8B;&#x4EF6;&#x3002;&#x5982;&#x4E0B;&#x662F;&#x4E00;&#x4E2A;&#x7B80;&#x5355;&#x7684;&#x793A;&#x4F8B;&#xFF1A;</p>
<blockquote>
<p>  Example: <em>levelFilterConfig.xml</em></p>
</blockquote>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">configuration</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">appender</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;CONSOLE&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;ch.qos.logback.core.ConsoleAppender&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">filter</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;ch.qos.logback.classic.filter.LevelFilter&quot;</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">level</span>&gt;</span>INFO<span class="hljs-tag">&lt;/<span class="hljs-name">level</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">onMatch</span>&gt;</span>ACCEPT<span class="hljs-tag">&lt;/<span class="hljs-name">onMatch</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">onMismatch</span>&gt;</span>DENY<span class="hljs-tag">&lt;/<span class="hljs-name">onMismatch</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">filter</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">encoder</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">pattern</span>&gt;</span>
        %-4relative [%thread] %-5level %logger{30} - %msg%n
      <span class="hljs-tag">&lt;/<span class="hljs-name">pattern</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">encoder</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">appender</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">root</span> <span class="hljs-attr">level</span>=<span class="hljs-string">&quot;DEBUG&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">appender-ref</span> <span class="hljs-attr">ref</span>=<span class="hljs-string">&quot;CONSOLE&quot;</span> /&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">root</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">configuration</span>&gt;</span>
</code></pre>
<h3 id="thresholdfilter">ThresholdFilter</h3>
<p><a href="https://logback.qos.ch/xref/ch/qos/logback/classic/filter/ThresholdFilter.html" target="_blank"><code>ThresholdFilter</code></a> &#x57FA;&#x4E8E;&#x7ED9;&#x5B9A;&#x7684;&#x4E34;&#x754C;&#x503C;&#x6765;&#x8FC7;&#x6EE4;&#x4E8B;&#x4EF6;&#x3002;&#x5982;&#x679C;&#x4E8B;&#x4EF6;&#x7684;&#x7EA7;&#x522B;&#x7B49;&#x4E8E;&#x6216;&#x9AD8;&#x4E8E;&#x7ED9;&#x5B9A;&#x7684;&#x4E34;&#x754C;&#x503C;&#xFF0C;&#x5F53;&#x8C03;&#x7528; <code>decide()</code> &#x65F6;&#xFF0C;<code>ThresholdFilter</code> &#x5C06;&#x4F1A;&#x8FD4;&#x56DE; NEUTRAL&#x3002;&#x4F46;&#x662F;&#x4E8B;&#x4EF6;&#x7684;&#x7EA7;&#x522B;&#x4F4E;&#x4E8E;&#x4E34;&#x754C;&#x503C;&#x5C06;&#x4F1A;&#x88AB;&#x62D2;&#x7EDD;&#x3002;&#x4E0B;&#x9762;&#x662F;&#x4E00;&#x4E2A;&#x7B80;&#x5355;&#x7684;&#x4F8B;&#x5B50;&#xFF1A;</p>
<blockquote>
<p>  Example: <em>thresholdFilterConfig.xml</em></p>
</blockquote>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">configuration</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">appender</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;CONSOLE&quot;</span>
    <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;ch.qos.logback.core.ConsoleAppender&quot;</span>&gt;</span>
    <span class="hljs-comment">&lt;!-- deny all events with a level below INFO, that is TRACE and DEBUG --&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">filter</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;ch.qos.logback.classic.filter.ThresholdFilter&quot;</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">level</span>&gt;</span>INFO<span class="hljs-tag">&lt;/<span class="hljs-name">level</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">filter</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">encoder</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">pattern</span>&gt;</span>
        %-4relative [%thread] %-5level %logger{30} - %msg%n
      <span class="hljs-tag">&lt;/<span class="hljs-name">pattern</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">encoder</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">appender</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">root</span> <span class="hljs-attr">level</span>=<span class="hljs-string">&quot;DEBUG&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">appender-ref</span> <span class="hljs-attr">ref</span>=<span class="hljs-string">&quot;CONSOLE&quot;</span> /&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">root</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">configuration</span>&gt;</span>
</code></pre>
<h2 id="evaluatorfilter">EvaluatorFilter</h2>
<p><a href="https://logback.qos.ch/xref/ch/qos/logback/core/filter/EvaluatorFilter.html" target="_blank"><code>EvaluatorFilter</code></a> &#x662F;&#x4E00;&#x4E2A;&#x901A;&#x7528;&#x7684;&#x8FC7;&#x6EE4;&#x5668;&#xFF0C;&#x5B83;&#x5C01;&#x88C5;&#x4E86;&#x4E00;&#x4E2A; <code>EventEvaluator</code>&#x3002;&#x987E;&#x540D;&#x601D;&#x4E49;&#xFF0C;<a href="https://logback.qos.ch/xref/ch/qos/logback/core/boolex/EventEvaluator.html" target="_blank"><code>EventEvaluator</code></a> &#x6839;&#x636E;&#x7ED9;&#x5B9A;&#x7684;&#x6807;&#x51C6;&#x6765;&#x8BC4;&#x4F30;&#x7ED9;&#x5B9A;&#x7684;&#x4E8B;&#x4EF6;&#x662F;&#x5426;&#x7B26;&#x5408;&#x6807;&#x51C6;&#x3002;&#x5728; match &#x548C; mismatch &#x7684;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;<code>EvaluatorFilter</code> &#x5C06;&#x4F1A;&#x8FD4;&#x56DE; <code>onMatch</code> &#x6216; <code>onMismatch</code> &#x6307;&#x5B9A;&#x7684;&#x503C;&#x3002;</p>
<p>&#x6CE8;&#x610F; <code>EventEvaluator</code> &#x662F;&#x4E00;&#x4E2A;&#x62BD;&#x8C61;&#x7C7B;&#x3002;&#x4F60;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x7EE7;&#x627F; <code>EventEvaluator</code> &#x6765;&#x5B9E;&#x73B0;&#x81EA;&#x5DF1;&#x4E8B;&#x4EF6;&#x8BC4;&#x4F30;&#x903B;&#x8F91;&#x3002;</p>
<h3 id="geventevaluator">GEventEvaluator</h3>
<p><a href="https://logback.qos.ch/xref/ch/qos/logback/classic/boolex/GEventEvaluator.html" target="_blank">GEventEvaluator</a> &#x662F; <a href="https://logback.qos.ch/xref/ch/qos/logback/core/boolex/EventEvaluator.html" target="_blank"><code>EventEvaluator</code></a> &#x5177;&#x4F53;&#x7684;&#x5B9E;&#x73B0;&#xFF0C;&#x5B83;&#x91C7;&#x7528; Groovy &#x8868;&#x8FBE;&#x5F0F;&#x4F5C;&#x4E3A;&#x8BC4;&#x4F30;&#x7684;&#x6807;&#x51C6;&#x3002;&#x6211;&#x4EEC;&#x628A; Groovy &#x8868;&#x8FBE;&#x5F0F;&#x79F0;&#x4E3A; &quot;Groovy &#x8BC4;&#x4F30;&#x8868;&#x8FBE;&#x5F0F;&quot;&#x3002;Groogy &#x8BC4;&#x4F30;&#x8868;&#x8FBE;&#x5F0F;&#x662F;&#x76EE;&#x524D;&#x4E3A;&#x6B62;&#x8FDB;&#x884C;&#x4E8B;&#x4EF6;&#x8FC7;&#x6EE4;&#x6700;&#x7075;&#x6D3B;&#x7684;&#x65B9;&#x5F0F;&#x3002;<code>GEventEvaluator</code> &#x9700;&#x8981; Groovy &#x8FD0;&#x884C;&#x73AF;&#x5883;&#x3002;&#x53C2;&#x8003;<a href="https://logback.qos.ch/setup.html#groovy" target="_blank">&#x76F8;&#x5173;&#x90E8;&#x5206;</a>&#x5728;&#x7C7B;&#x8DEF;&#x5F84;&#x4E0B;&#x6DFB;&#x52A0; Groovy &#x8FD0;&#x884C;&#x73AF;&#x5883;&#x3002;</p>
<p>&#x8BC4;&#x4F30;&#x8868;&#x8FBE;&#x5F0F;&#x5728;&#x89E3;&#x6790;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x671F;&#x95F4;&#x88AB;&#x52A8;&#x6001;&#x7F16;&#x8BD1;&#x3002;&#x4F5C;&#x4E3A;&#x7528;&#x6237;&#xFF0C;&#x4E0D;&#x9700;&#x8981;&#x8003;&#x8651;&#x5B9E;&#x9645;&#x7684;&#x60C5;&#x51B5;&#x3002;&#x4F46;&#x662F;&#xFF0C;&#x4F60;&#x9700;&#x8981;&#x786E;&#x4FDD;&#x4F60;&#x7684; Groovy &#x8868;&#x8FBE;&#x5F0F;&#x662F;&#x6709;&#x6548;&#x7684;&#x3002;</p>
<p>&#x8BC4;&#x4F30;&#x8868;&#x8FBE;&#x5F0F;&#x4F5C;&#x7528;&#x4E8E;&#x5F53;&#x524D;&#x7684;&#x65E5;&#x5FD7;&#x4E8B;&#x4EF6;&#x3002;logback &#x4F1A;&#x81EA;&#x52A8;&#x5C06; <a href="https://logback.qos.ch/apidocs/ch/qos/logback/classic/spi/ILoggingEvent.html" target="_blank">ILoggingEvent</a> &#x7C7B;&#x578B;&#x7684;&#x65E5;&#x5FD7;&#x4E8B;&#x4EF6;&#x4F5C;&#x4E3A;&#x53D8;&#x91CF;&#x63D2;&#x5165;&#xFF0C;&#x5F15;&#x7528;&#x5230; &apos;event&apos; &#x6216;&#x8005;&#x5B83;&#x7684;&#x7B80;&#x79F0; &apos;e&apos;&#x3002;TRACE, DEBUG, INFO, WARN &#x4EE5;&#x53CA; ERROR &#x4E5F;&#x80FD;&#x591F;&#x88AB;&#x5BFC;&#x5165;&#x5230;&#x8868;&#x8FBE;&#x5F0F;&#x7684;&#x8303;&#x56F4;&#x4E2D;&#x3002;&#x6240;&#x4EE5;&#xFF0C;&quot;event.level == DEBUG&quot; &#x4E0E; &quot;e.level == DEBUG&quot; &#x662F;&#x7B49;&#x4EF7;&#x7684;&#x3002;&#x53EA;&#x6709;&#x5F53;&#x5F53;&#x524D;&#x65E5;&#x5FD7;&#x4E8B;&#x4EF6;&#x7684;&#x7EA7;&#x522B;&#x4E3A; DEBUG &#x65F6;&#xFF0C;Groovy &#x8868;&#x8FBE;&#x5F0F;&#x624D;&#x4F1A;&#x8FD4;&#x56DE; <code>true</code>&#x3002;&#x5BF9;&#x4E8E;&#x5176;&#x5B83;&#x7684;&#x7EA7;&#x522B;&#x6BD4;&#x8F83;&#x64CD;&#x4F5C;&#xFF0C;&#x5E94;&#x8BE5;&#x901A;&#x8FC7; <code>toInt()</code> &#x64CD;&#x4F5C;&#x5C06; level &#x5B57;&#x6BB5;&#x8F6C;&#x53D8;&#x4E3A;&#x6574;&#x578B;&#x3002;</p>
<p>&#x4E0B;&#x9762;&#x662F;&#x4E00;&#x4E2A;&#x6BD4;&#x8F83;&#x590D;&#x6742;&#x7684;&#x4F8B;&#x5B50;&#xFF1A;</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">configuration</span>&gt;</span>

  <span class="hljs-tag">&lt;<span class="hljs-name">appender</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;STDOUT&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;ch.qos.logback.core.ConsoleAppender&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">filter</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;ch.qos.logback.core.filter.EvaluatorFilter&quot;</span>&gt;</span>      
      <span class="hljs-tag">&lt;<span class="hljs-name">evaluator</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;ch.qos.logback.classic.boolex.GEventEvaluator&quot;</span>&gt;</span> 
        <span class="hljs-tag">&lt;<span class="hljs-name">expression</span>&gt;</span>
           e.level.toInt() &gt;= WARN.toInt() &amp;amp;&amp;amp;  <span class="hljs-comment">&lt;!-- &#x5728; XML &#x4E2D;&#x66FF;&#x4EE3; &amp;&amp; --&gt;</span>
           !(e.mdc?.get(&quot;req.userAgent&quot;) =~ /Googlebot|msnbot|Yahoo/ )
        <span class="hljs-tag">&lt;/<span class="hljs-name">expression</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">evaluator</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">OnMismatch</span>&gt;</span>DENY<span class="hljs-tag">&lt;/<span class="hljs-name">OnMismatch</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">OnMatch</span>&gt;</span>NEUTRAL<span class="hljs-tag">&lt;/<span class="hljs-name">OnMatch</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">filter</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">encoder</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">pattern</span>&gt;</span>
        %-4relative [%thread] %-5level %logger - %msg%n
      <span class="hljs-tag">&lt;/<span class="hljs-name">pattern</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">encoder</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">appender</span>&gt;</span>

  <span class="hljs-tag">&lt;<span class="hljs-name">root</span> <span class="hljs-attr">level</span>=<span class="hljs-string">&quot;DEBUG&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">appender-ref</span> <span class="hljs-attr">ref</span>=<span class="hljs-string">&quot;STDOUT&quot;</span> /&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">root</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">configuration</span>&gt;</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x7684;&#x8FC7;&#x6EE4;&#x5668;&#x4F1A;&#x8BA9;&#x7EA7;&#x522B;&#x5728; WARN &#x53CA;&#x4EE5;&#x4E0A;&#x7684;&#x65E5;&#x5FD7;&#x4E8B;&#x4EF6;&#x5728;&#x63A7;&#x5236;&#x53F0;&#x663E;&#x793A;&#xFF0C;&#x9664;&#x975E;&#x662F;&#x7531;&#x4E8E;&#x6765;&#x81EA; Google&#xFF0C;MSN&#xFF0C;Yahoo &#x7684;&#x7F51;&#x7EDC;&#x722C;&#x866B;&#x5BFC;&#x81F4;&#x7684;&#x9519;&#x8BEF;&#x3002;&#x5B83;&#x901A;&#x8FC7;&#x68C0;&#x67E5;&#x4E0E;&#x4E8B;&#x4EF6;&#x76F8;&#x5173;&#x7684; MDC &#x5305;&#x542B; &quot;req.userAgent&quot; &#x7684;&#x503C;&#x662F;&#x5426;&#x5339;&#x914D; <code>/Googlebot|msbbot|Yahoo/</code> &#x6B63;&#x5219;&#x8868;&#x8FBE;&#x5F0F;&#x3002;&#x56E0;&#x4E3A; MDC &#x7684;&#x6620;&#x5C04;&#x53EF;&#x80FD;&#x4E3A; null&#xFF0C;&#x6240;&#x4EE5;&#x6211;&#x4EEC;&#x4F7F;&#x7528; Groovy &#x7684;<a href="http://groovy.codehaus.org/Null+Object+Pattern" target="_blank">&#x5B89;&#x5168;&#x89E3;&#x5F15;&#x7528;&#x64CD;&#x4F5C;&#x7B26;</a>&#xFF0C;&#x4E5F;&#x5C31;&#x662F; <code>?.</code> &#x64CD;&#x4F5C;&#x7B26;&#x3002;&#x8FD9;&#x4E2A;&#x76F8;&#x7B49;&#x7684;&#x903B;&#x8F91;&#x5728; Java &#x4E2D;&#x7684;&#x8868;&#x8FBE;&#x5F0F;&#x66F4;&#x957F;&#x3002;</p>
<p>&#x5982;&#x679C;&#x4F60;&#x597D;&#x5947; user agent &#x6807;&#x8BC6;&#x7B26;&#x4F5C;&#x4E3A;&#x503C;&#x600E;&#x6837;&#x88AB;&#x63D2;&#x5165;&#x5230; key &#x4E3A; &quot;req.userAgent &quot; &#x7684; MDC &#x4E2D;&#xFF0C;&#x90A3;&#x4E48;&#x5C31;&#x4F1A;&#x6D89;&#x53CA;&#x5230; logback &#x4E3A;&#x4E86;&#x8FD9;&#x4E2A;&#x76EE;&#x7684;&#x9644;&#x5E26;&#x4E86;&#x4E00;&#x4E2A;&#x540D;&#x4E3A; <a href="https://logback.qos.ch/manual/mdc.html#mis" target="_blank"><code>MDCInsertingServletFilter</code></a> &#x7684; servlet &#x8FC7;&#x6EE4;&#x5668;&#x3002;&#x5B83;&#x5C06;&#x4F1A;&#x5728;&#x63A5;&#x4E0B;&#x6765;&#x7684;&#x7AE0;&#x8282;&#x4E2D;&#x63CF;&#x8FF0;&#x3002;</p>
<h3 id="janinoeventevaluator">JaninoEventEvaluator</h3>
<p>logback-classic &#x9644;&#x5E26;&#x7684;&#x53E6;&#x5916;&#x4E00;&#x4E2A; <code>EventEvaluator</code> &#x7684;&#x5177;&#x4F53;&#x5B9E;&#x73B0;&#x540D;&#x4E3A; <a href="https://logback.qos.ch/xref/ch/qos/logback/classic/boolex/JaninoEventEvaluator.html" target="_blank">JaninoEventEvaluator</a>&#xFF0C;&#x5B83;&#x63A5;&#x53D7;&#x4EFB;&#x610F;&#x8FD4;&#x56DE;&#x5E03;&#x5C14;&#x503C;&#x7684; Java &#x4EE3;&#x7801;&#x5757;&#x4F5C;&#x4E3A;&#x8BC4;&#x5224;&#x6807;&#x51C6;&#x3002;&#x6211;&#x4EEC;&#x628A;&#x8FD9;&#x79CD; Java &#x5E03;&#x5C14;&#x8868;&#x8FBE;&#x5F0F;&#x79F0;&#x4E3A; &quot;<em>&#x8BC4;&#x4F30;&#x8868;&#x8FBE;&#x5F0F;</em>&quot;&#x3002;&#x8BC4;&#x4F30;&#x8868;&#x8FBE;&#x5F0F;&#x5728;&#x4E8B;&#x4EF6;&#x8FC7;&#x6EE4;&#x4E2D;&#x53EF;&#x4EE5;&#x66F4;&#x52A0;&#x7684;&#x7075;&#x6D3B;&#x3002;<code>JaninoEventEvaluator</code> &#x9700;&#x8981; <a href="http://docs.codehaus.org/display/JANINO/Home" target="_blank">Janino &#x7C7B;&#x5E93;</a>&#x3002;&#x8BF7;&#x53C2;&#x89C1;<a href="https://logback.qos.ch/setup.html#janino" target="_blank">&#x76F8;&#x5173;&#x7AE0;&#x8282;</a>&#x8FDB;&#x884C;&#x8BBE;&#x7F6E;&#x3002;&#x8DDF; <code>JaninoEventEvaluator</code> &#x76F8;&#x6BD4;&#xFF0C;<code>GEventEvaluator</code> &#x4F7F;&#x7528; Groovy &#x8BED;&#x8A00;&#xFF0C;&#x4F7F;&#x7528;&#x8D77;&#x6765;&#x975E;&#x5E38;&#x65B9;&#x4FBF;&#x3002;&#x4F46;&#x662F; <code>JaninoEventEvaluator</code> &#x5C06;&#x4F7F;&#x7528;&#x8FD0;&#x884C;&#x66F4;&#x5FEB;&#x7684;&#x7B49;&#x6548;&#x8868;&#x8FBE;&#x5F0F;&#x3002;</p>
<p>&#x8BC4;&#x4F30;&#x8868;&#x8FBE;&#x5F0F;&#x5728;&#x89E3;&#x6790;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x671F;&#x95F4;&#x88AB;&#x52A8;&#x6001;&#x7F16;&#x8BD1;&#x3002;&#x4F5C;&#x4E3A;&#x7528;&#x6237;&#xFF0C;&#x4E0D;&#x9700;&#x8981;&#x8003;&#x8651;&#x5B9E;&#x9645;&#x7684;&#x60C5;&#x51B5;&#x3002;&#x4F46;&#x662F;&#xFF0C;&#x4F60;&#x9700;&#x8981;&#x786E;&#x4FDD;&#x4F60;&#x7684; Java &#x8868;&#x8FBE;&#x5F0F;&#x662F;&#x6709;&#x6548;&#x7684;&#xFF0C;&#x4FDD;&#x8BC1;&#x5B83;&#x7684;&#x8BC4;&#x4F30;&#x7ED3;&#x679C;&#x4E3A; true &#x6216; false&#x3002;</p>
<p>&#x8BC4;&#x4F30;&#x8868;&#x8FBE;&#x5F0F;&#x5BF9;&#x5F53;&#x524D;&#x65E5;&#x5FD7;&#x4E8B;&#x4EF6;&#x8FDB;&#x884C;&#x8BC4;&#x4F30;&#x3002;logback-classic &#x81EA;&#x52A8;&#x5BFC;&#x51FA;&#x65E5;&#x5FD7;&#x4E8B;&#x4EF6;&#x7684;&#x5404;&#x79CD;&#x5B57;&#x6BB5;&#x4F5C;&#x4E3A;&#x53D8;&#x91CF;&#xFF0C;&#x4E3A;&#x4E86;&#x53EF;&#x4EE5;&#x4ECE;&#x8BC4;&#x4F30;&#x8868;&#x8FBE;&#x5F0F;&#x8BBF;&#x95EE;&#x3002;&#x8FD9;&#x4E9B;&#x5BFC;&#x51FA;&#x7684;&#x53D8;&#x91CF;&#x662F;&#x5927;&#x5C0F;&#x5199;&#x654F;&#x611F;&#x7684;&#xFF0C;&#x5982;&#x4E0B;&#x8868;&#x6240;&#x793A;&#xFF1A;</p>
<table>
<thead>
<tr>
<th>&#x540D;&#x5B57;</th>
<th>&#x7C7B;&#x578B;</th>
<th>&#x63CF;&#x8FF0;</th>
</tr>
</thead>
<tbody>
<tr>
<td>event</td>
<td><code>LoggingEvent</code></td>
<td>&#x65E5;&#x5FD7;&#x8BF7;&#x6C42;&#x7684;&#x539F;&#x59CB;&#x65E5;&#x5FD7;&#x4E8B;&#x4EF6;&#x3002;&#x4E0B;&#x9762;&#x6240;&#x6709;&#x7684;&#x53D8;&#x91CF;&#x90FD;&#x6765;&#x81EA;&#x8FD9;&#x4E2A;&#x65E5;&#x5FD7;&#x4E8B;&#x4EF6;&#x3002;&#x4F8B;&#x5982;&#xFF0C;<code>event.getMessage()</code> &#x8FD4;&#x56DE;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#x8DDF;&#x4E0B;&#x9762;&#x7684; <code>message</code> &#x53D8;&#x91CF;&#x8FD4;&#x56DE;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#x4E00;&#x6837;&#x3002;</td>
</tr>
<tr>
<td>message</td>
<td><code>String</code></td>
<td>&#x65E5;&#x5FD7;&#x8BF7;&#x6C42;&#x7684;&#x539F;&#x59CB;&#x4FE1;&#x606F;&#x3002;&#x4F8B;&#x5982;&#xFF0C;&#x5BF9;&#x4E8E; logger <em>I</em>&#xFF0C;&#x5F53;&#x4F60;&#x5199;&#x7684;&#x662F; I.info(&quot;Hello {}&quot;, name); &#x65F6;&#xFF0C;name &#x7684;&#x503C;&#x88AB;&#x6307;&#x5B9A;&#x4E3A; &quot;Alice&quot;&#xFF0C;&#x6D88;&#x606F;&#x5C31;&#x4E3A; &quot;Hello {}&quot;&#x3002;</td>
</tr>
<tr>
<td>formattedMessage</td>
<td><code>String</code></td>
<td>&#x65E5;&#x5FD7;&#x8BF7;&#x6C42;&#x4E2D;&#x683C;&#x5F0F;&#x5316;&#x540E;&#x7684;&#x6D88;&#x606F;&#x3002;&#x4F8B;&#x5982;&#xFF0C;&#x5BF9;&#x4E8E; logger <em>I</em>&#xFF0C;&#x5F53;&#x4F60;&#x5199;&#x7684;&#x662F; I.info(&quot;Hello {}&quot;, name); &#x65F6;&#xFF0C;name &#x7684;&#x503C;&#x88AB;&#x6307;&#x5B9A;&#x4E3A; &quot;Alice&quot;&#xFF0C;&#x683C;&#x5F0F;&#x5316;&#x540E;&#x7684;&#x6D88;&#x606F;&#x5C31;&#x4E3A; &quot;Hello Alice&quot;&#x3002;</td>
</tr>
<tr>
<td>logger</td>
<td><code>String</code></td>
<td>logger &#x7684;&#x540D;&#x5B57;</td>
</tr>
<tr>
<td>loggerContext</td>
<td><a href="https://logback.qos.ch/xref/ch/qos/logback/classic/spi/LoggerContextVO.html" target="_blank"><code>LoggerContextVO</code></a></td>
<td>&#x65E5;&#x5FD7;&#x4E8B;&#x4EF6;&#x5C5E;&#x4E8E; logger &#x4E0A;&#x4E0B;&#x6587;&#x4E2D;&#x54EA;&#x4E2A;&#x53D7;&#x9650;&#x7684;&#x89C6;&#x56FE; (&#x503C;&#x5BF9;&#x8C61;)</td>
</tr>
<tr>
<td>level</td>
<td><code>int</code></td>
<td>&#x4E8B;&#x4EF6;&#x7EA7;&#x522B;&#x5BF9;&#x5E94;&#x7684; int &#x503C;&#x3002;&#x7528;&#x6765;&#x521B;&#x5EFA;&#x5305;&#x542B;&#x7EA7;&#x522B;&#x7684;&#x8868;&#x8FBE;&#x5F0F;&#x3002;&#x9ED8;&#x8BA4;&#x503C;&#x662F; DEBUG&#xFF0C;INFO&#xFF0C;WARN &#x4EE5;&#x53CA; ERROR &#x4E5F;&#x662F;&#x6709;&#x6548;&#x7684;&#x3002;&#x6240;&#x4EE5; <em>level &gt; INFO</em> &#x662F;&#x6709;&#x6548;&#x7684;&#x8868;&#x8FBE;&#x5F0F;&#x3002;</td>
</tr>
<tr>
<td>timeStamp</td>
<td><code>long</code></td>
<td>&#x65E5;&#x5FD7;&#x4E8B;&#x4EF6;&#x521B;&#x5EFA;&#x7684;&#x65F6;&#x95F4;</td>
</tr>
<tr>
<td>marker</td>
<td><code>Marker</code></td>
<td>&#x4E0E;&#x65E5;&#x5FD7;&#x8BF7;&#x6C42;&#x76F8;&#x5173;&#x7684; <code>Marker</code> &#x5BF9;&#x8C61;&#x3002;&#x6CE8;&#x610F;&#xFF0C;marker &#x53EF;&#x80FD;&#x4F1A;&#x4E3A; null&#xFF0C;&#x56E0;&#x6B64;&#x4F60;&#x9700;&#x8981;&#x5BF9;&#x8FD9;&#x79CD;&#x60C5;&#x51B5;&#x8FDB;&#x884C;&#x68C0;&#x67E5;&#xFF0C;&#x8FDB;&#x800C;&#x907F;&#x514D;  <code>NullPointerException</code>&#x3002;</td>
</tr>
<tr>
<td>mdc</td>
<td><code>Map</code></td>
<td>&#x521B;&#x5EFA;&#x65E5;&#x5FD7;&#x4E8B;&#x4EF6;&#x65F6;&#x5305;&#x542B;&#x7684;&#x6240;&#x6709;&#x7684; MDC &#x503C;&#x7684;&#x4E00;&#x4E2A;&#x6620;&#x5C04;&#x3002;&#x53EF;&#x4EE5;&#x901A;&#x8FC7; <em>mdc.get(&quot;myKey&quot;)</em> &#x6765;&#x83B7;&#x53D6; MDC &#x4E2D;&#x5BF9;&#x5E94;&#x7684;&#x503C;&#x3002;&#x5728; 0.9.30 &#x7248;&#x672C;&#x7684; logback-classic&#xFF0C;mdc &#x53D8;&#x91CF;&#x6C38;&#x8FDC;&#x4E0D;&#x4F1A;&#x4E3A; null&#x3002;<br><code>java.util.Map</code> &#x7C7B;&#x578B;&#x662F;&#x975E;&#x53C2;&#x6570;&#x5316;&#x7684;&#xFF0C;&#x56E0;&#x4E3A; Janino &#x4E0D;&#x652F;&#x6301;&#x6CDB;&#x578B;&#x3002;&#x56E0;&#x6B64;&#xFF0C;<code>mdc.get()</code> &#x8FD4;&#x56DE;&#x503C;&#x7684;&#x7C7B;&#x578B;&#x662F; <code>Object</code> &#x800C;&#x4E0D;&#x662F; <code>String</code>&#x3002;&#x4F46;&#x662F;&#x53EF;&#x4EE5;&#x5C06;&#x8FD4;&#x56DE;&#x503C;&#x5F3A;&#x5236;&#x8F6C;&#x6362;&#x4E3A; <code>String</code>&#x3002;&#x4F8B;&#x5982;&#xFF0C; <code>((String) mdc.get(&quot;k&quot;)).contains(&quot;val&quot;)</code>&#x3002;</td>
</tr>
<tr>
<td>throwable</td>
<td>java.lang.Throwable</td>
<td>&#x5982;&#x679C;&#x65E5;&#x5FD7;&#x4E8B;&#x4EF6;&#x6CA1;&#x6709;&#x76F8;&#x5173;&#x7684;&#x5F02;&#x5E38;&#xFF0C;&#x90A3;&#x4E48;&#x53D8;&#x91CF; &quot;throwable&quot; &#x7684;&#x503C;&#x4E3A; null&#x3002;&quot;throwable&quot; &#x4E0D;&#x53EF;&#x4EE5;&#x88AB;&#x5E8F;&#x5217;&#x5316;&#x3002;&#x6240;&#x4EE5;&#x5728;&#x8FDC;&#x7A0B;&#x670D;&#x52A1;&#x5668;&#x4E0A;&#xFF0C;&#x8FD9;&#x4E2A;&#x503C;&#x6C38;&#x8FDC;&#x4E3A; null&#x3002;&#x60F3;&#x8981;&#x4F7F;&#x7528;&#x4E0E;&#x4F4D;&#x7F6E;&#x65E0;&#x5173;&#x7684;&#x8868;&#x8FBE;&#x5F0F;&#xFF0C;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x4E0B;&#x9762;&#x7684; <code>throwableProxy</code>&#x3002;</td>
</tr>
<tr>
<td>throwableProxy</td>
<td><a href="https://logback.qos.ch/xref/ch/qos/logback/classic/spi/IThrowableProxy.html" target="_blank"><code>IThrowableProxy</code></a></td>
<td>&#x65E5;&#x5FD7;&#x4E8B;&#x4EF6;&#x7684;&#x5F02;&#x5E38;&#x4EE3;&#x7406;&#x3002;&#x5982;&#x679C;&#x65E5;&#x5FD7;&#x4E8B;&#x4EF6;&#x6CA1;&#x6709;&#x76F8;&#x5173;&#x7684;&#x5F02;&#x5E38;&#xFF0C;&#x90A3;&#x4E48; <code>throwableProxy</code> &#x7684;&#x503C;&#x4E3A; null&#x3002;&#x4E0E; &quot;throwable&quot; &#x76F8;&#x53CD;&#xFF0C;&#x5373;&#x4F7F;&#x5728;&#x8FDC;&#x7A0B;&#x670D;&#x52A1;&#x5668;&#x4E0A;&#x5E8F;&#x5217;&#x5316;&#x4E4B;&#x540E;&#xFF0C;&#x65E5;&#x5FD7;&#x4E8B;&#x4EF6;&#x76F8;&#x5173;&#x7684;&#x5F02;&#x5E38;&#x4E5F;&#x4E0D;&#x4F1A;&#x4E3A; null&#x3002;</td>
</tr>
</tbody>
</table>
<p>&#x4E0B;&#x9762;&#x662F;&#x5177;&#x4F53;&#x7684;&#x4F8B;&#x5B50;&#x3002;</p>
<blockquote>
<p>Example: <em>basicEventEvaluator.xml</em></p>
</blockquote>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">configuration</span>&gt;</span>

  <span class="hljs-tag">&lt;<span class="hljs-name">appender</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;STDOUT&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;ch.qos.logback.core.ConsoleAppender&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">filter</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;ch.qos.logback.core.filter.EvaluatorFilter&quot;</span>&gt;</span>      
      <span class="hljs-tag">&lt;<span class="hljs-name">evaluator</span>&gt;</span> <span class="hljs-comment">&lt;!-- defaults to type ch.qos.logback.classic.boolex.JaninoEventEvaluator --&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">expression</span>&gt;</span>return message.contains(&quot;billing&quot;);<span class="hljs-tag">&lt;/<span class="hljs-name">expression</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">evaluator</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">OnMismatch</span>&gt;</span>NEUTRAL<span class="hljs-tag">&lt;/<span class="hljs-name">OnMismatch</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">OnMatch</span>&gt;</span>DENY<span class="hljs-tag">&lt;/<span class="hljs-name">OnMatch</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">filter</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">encoder</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">pattern</span>&gt;</span>
        %-4relative [%thread] %-5level %logger - %msg%n
      <span class="hljs-tag">&lt;/<span class="hljs-name">pattern</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">encoder</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">appender</span>&gt;</span>

  <span class="hljs-tag">&lt;<span class="hljs-name">root</span> <span class="hljs-attr">level</span>=<span class="hljs-string">&quot;INFO&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">appender-ref</span> <span class="hljs-attr">ref</span>=<span class="hljs-string">&quot;STDOUT&quot;</span> /&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">root</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">configuration</span>&gt;</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x7684;&#x914D;&#x7F6E;&#x5C06; <code>EvaluatorFilter</code> &#x6DFB;&#x52A0;&#x5230; <code>ConsoleAppender</code>&#x3002;&#x4E00;&#x4E2A;&#x7C7B;&#x578B;&#x4E3A; <code>JaninoEventEvaluator</code> &#x7684; evaluator &#x4E4B;&#x540E;&#x88AB;&#x6CE8;&#x5165;&#x5230; <code>EvaluatorFilter</code> &#x4E2D;&#x3002;<code>&lt;evaluator</code> &#x5728;&#x7F3A;&#x5C11; <em>class</em> &#x5C5E;&#x6027;&#x7684;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;Joran &#x4F1A;&#x6307;&#x5B9A; evaluator &#x7684;&#x9ED8;&#x8BA4;&#x7C7B;&#x578B;&#x4E3A; <code>JaninoEventEvaluator</code>&#x3002;&#x8FD9;&#x662F;<a href="https://logback.qos.ch/manual/onJoran.html#defaultClassMapping" target="_blank">&#x5C11;&#x6570;&#x51E0;&#x4E2A;</a>&#x9700;&#x8981; Joran &#x9ED8;&#x8BA4;&#x6307;&#x5B9A;&#x7C7B;&#x578B;&#x7684;&#x7EC4;&#x4EF6;&#x3002;</p>
<p><em>expression</em> &#x5143;&#x7D20;&#x5BF9;&#x5E94;&#x521A;&#x624D;&#x8BA8;&#x8BBA;&#x8FC7;&#x7684;&#x8BC4;&#x4F30;&#x8868;&#x8FBE;&#x5F0F;&#x3002;&#x8868;&#x8FBE;&#x5F0F; <code>return message.contains(&quot;billing&quot;);</code> &#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x5E03;&#x5C14;&#x503C;&#x3002;<em>message</em> &#x53D8;&#x91CF;&#x4F1A;&#x88AB; <code>JaninoEventEvaluator</code> &#x81EA;&#x52A8;&#x5BFC;&#x51FA;&#x3002;</p>
<p>&#x7531;&#x4E8E; <code>OnMismatch</code> &#x5C5E;&#x6027;&#x7684;&#x503C;&#x4E3A; NEUTRAL &#x4EE5;&#x53CA; <code>OnMatch</code> &#x5C5E;&#x6027;&#x7684;&#x503C;&#x4E3A; DENY&#xFF0C;&#x6240;&#x4EE5;&#x8BC4;&#x4F30;&#x8FC7;&#x6EE4;&#x5668;&#x4F1A;&#x4E22;&#x6389;&#x6D88;&#x606F;&#x5305;&#x542B; &quot;billing&quot; &#x7684;&#x65E5;&#x5FD7;&#x4E8B;&#x4EF6;&#x3002;</p>
<p><a href="https://logback.qos.ch/xref/chapters/filters/FilterEvents.html" target="_blank">FilterEvents</a> &#x53D1;&#x51FA;&#x5341;&#x6761;&#x65E5;&#x5FD7;&#x8BF7;&#x6C42;&#xFF0C;&#x7F16;&#x53F7;&#x4E3A; 0 &#x5230; 9&#x3002;&#x9996;&#x5148;&#x5728;&#x6CA1;&#x6709;&#x8FC7;&#x6EE4;&#x5668;&#x7684;&#x60C5;&#x51B5;&#x4E0B;&#x8FD0;&#x884C; <code>FilterEvents</code>&#xFF1A;</p>
<pre><code>java chapters.filters.FilterEvents src/main/java/chapters/filters/basicConfiguration.xml
</code></pre><p>&#x8F93;&#x51FA;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-java"><span class="hljs-number">0</span>    [main] INFO  chapters.filters.FilterEvents - logging statement <span class="hljs-number">0</span>
<span class="hljs-number">0</span>    [main] INFO  chapters.filters.FilterEvents - logging statement <span class="hljs-number">1</span>
<span class="hljs-number">0</span>    [main] INFO  chapters.filters.FilterEvents - logging statement <span class="hljs-number">2</span>
<span class="hljs-number">0</span>    [main] DEBUG chapters.filters.FilterEvents - logging statement <span class="hljs-number">3</span>
<span class="hljs-number">0</span>    [main] INFO  chapters.filters.FilterEvents - logging statement <span class="hljs-number">4</span>
<span class="hljs-number">0</span>    [main] INFO  chapters.filters.FilterEvents - logging statement <span class="hljs-number">5</span>
<span class="hljs-number">0</span>    [main] ERROR chapters.filters.FilterEvents - billing statement <span class="hljs-number">6</span>
<span class="hljs-number">0</span>    [main] INFO  chapters.filters.FilterEvents - logging statement <span class="hljs-number">7</span>
<span class="hljs-number">0</span>    [main] INFO  chapters.filters.FilterEvents - logging statement <span class="hljs-number">8</span>
<span class="hljs-number">0</span>    [main] INFO  chapters.filters.FilterEvents - logging statement <span class="hljs-number">9</span>
</code></pre>
<p>&#x5047;&#x8BBE;&#x6211;&#x4EEC;&#x60F3;&#x8981;&#x4E22;&#x5F03; &quot;billing statement&quot;&#x3002;<em>basicEventEvaluator.xml</em> &#x4E2D;&#x914D;&#x7F6E;&#x7684;&#x8FC7;&#x6EE4;&#x5668;&#x6070;&#x597D;&#x53EF;&#x4EE5;&#x6EE1;&#x8DB3;&#x8FD9;&#x4E2A;&#x9700;&#x6C42;&#x3002;</p>
<p>&#x901A;&#x8FC7; <em>basicEventEvaluator.xml</em> &#x8FD0;&#x884C;&#xFF1A;</p>
<pre><code class="lang-bash">java chapters.filters.FilterEvents src/main/java/chapters/filters/basicEventEvaluator.xml
</code></pre>
<p>&#x5C06;&#x4F1A;&#x5F97;&#x5230;&#xFF1A;</p>
<pre><code class="lang-java"><span class="hljs-number">0</span>    [main] INFO  chapters.filters.FilterEvents - logging statement <span class="hljs-number">0</span>
<span class="hljs-number">0</span>    [main] INFO  chapters.filters.FilterEvents - logging statement <span class="hljs-number">1</span>
<span class="hljs-number">0</span>    [main] INFO  chapters.filters.FilterEvents - logging statement <span class="hljs-number">2</span>
<span class="hljs-number">0</span>    [main] DEBUG chapters.filters.FilterEvents - logging statement <span class="hljs-number">3</span>
<span class="hljs-number">0</span>    [main] INFO  chapters.filters.FilterEvents - logging statement <span class="hljs-number">4</span>
<span class="hljs-number">0</span>    [main] INFO  chapters.filters.FilterEvents - logging statement <span class="hljs-number">5</span>
<span class="hljs-number">0</span>    [main] INFO  chapters.filters.FilterEvents - logging statement <span class="hljs-number">7</span>
<span class="hljs-number">0</span>    [main] INFO  chapters.filters.FilterEvents - logging statement <span class="hljs-number">8</span>
<span class="hljs-number">0</span>    [main] INFO  chapters.filters.FilterEvents - logging statement <span class="hljs-number">9</span>
</code></pre>
<p>&#x8BC4;&#x4F30;&#x8868;&#x8FBE;&#x5F0F;&#x53EF;&#x4EE5;&#x662F;&#x4E00;&#x4E2A; Java &#x4EE3;&#x7801;&#x5757;&#x3002;&#x5982;&#x4E0B;&#xFF0C;&#x4FBF;&#x662F;&#x4E00;&#x4E2A;&#x6709;&#x6548;&#x7684;&#x8868;&#x8FBE;&#x5F0F;&#x3002;</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">evaluator</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">expression</span>&gt;</span>
    if(logger.startsWith(&quot;org.apache.http&quot;))
      return true;

    if(mdc == null || mdc.get(&quot;entity&quot;) == null)
      return false;

    String payee = (String) mdc.get(&quot;entity&quot;);

    if(logger.equals(&quot;org.apache.http.wire&quot;) &amp;amp;&amp;amp;
        payee.contains(&quot;someSpecialValue&quot;) &amp;amp;&amp;amp;
        !message.contains(&quot;someSecret&quot;)) {
      return true;
    }

    return false;
  <span class="hljs-tag">&lt;/<span class="hljs-name">expression</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">evaluator</span>&gt;</span>
</code></pre>
<h2 id="matchers">Matchers</h2>
<p>&#x867D;&#x7136;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x8C03;&#x7528; <code>String</code> &#x7C7B;&#x7684; <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html#matches%28java.lang.String%29" target="_blank">matches()</a> &#x65B9;&#x6CD5;&#x6765;&#x8FDB;&#x884C;&#x6A21;&#x5F0F;&#x5339;&#x914D;&#xFF0C;&#x4F46;&#x662F;&#x6BCF;&#x6B21;&#x8C03;&#x7528; filter &#x90FD;&#x9700;&#x8981;&#x8017;&#x8D39;&#x65F6;&#x95F4;&#x91CD;&#x65B0;&#x7F16;&#x8BD1;&#x4E00;&#x4E2A;&#x65B0;&#x7684; <code>Pattern</code> &#x5BF9;&#x8C61;&#x3002;&#x4E3A;&#x4E86;&#x6D88;&#x9664;&#x8FD9;&#x79CD;&#x5F71;&#x54CD;&#xFF0C;&#x4F60;&#x53EF;&#x4EE5;&#x9884;&#x5148;&#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x6216;&#x8005;&#x591A;&#x4E2A; <a href="https://logback.qos.ch/xref/ch/qos/logback/core/boolex/Matcher.html" target="_blank">Matcher</a> &#x5BF9;&#x8C61;&#x3002;&#x4E00;&#x65E6;&#x5B9A;&#x4E49;&#x4E86;&#x4E00;&#x4E2A; matcher&#xFF0C;&#x5C31;&#x53EF;&#x4EE5;&#x5728;&#x8BC4;&#x4F30;&#x8868;&#x8FBE;&#x5F0F;&#x4E2D;&#x91CD;&#x590D;&#x4F7F;&#x7528;&#x4E86;&#x3002;</p>
<p>&#x901A;&#x8FC7;&#x4E00;&#x4E2A;&#x7B80;&#x5355;&#x7684;&#x4F8B;&#x5B50;&#x6765;&#x8BF4;&#x660E;&#x8FD9;&#x4E00;&#x70B9;&#xFF1A;</p>
<blockquote>
<p>  Example: <em>evaluatorWithMatcher.xml</em></p>
</blockquote>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">configuration</span> <span class="hljs-attr">debug</span>=<span class="hljs-string">&quot;true&quot;</span>&gt;</span>

  <span class="hljs-tag">&lt;<span class="hljs-name">appender</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;STDOUT&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;ch.qos.logback.core.ConsoleAppender&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">filter</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;ch.qos.logback.core.filter.EvaluatorFilter&quot;</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">evaluator</span>&gt;</span>        
        <span class="hljs-tag">&lt;<span class="hljs-name">matcher</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">Name</span>&gt;</span>odd<span class="hljs-tag">&lt;/<span class="hljs-name">Name</span>&gt;</span>
          <span class="hljs-comment">&lt;!-- filter out odd numbered statements --&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">regex</span>&gt;</span>statement [13579]<span class="hljs-tag">&lt;/<span class="hljs-name">regex</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">matcher</span>&gt;</span>

        <span class="hljs-tag">&lt;<span class="hljs-name">expression</span>&gt;</span>odd.matches(formattedMessage)<span class="hljs-tag">&lt;/<span class="hljs-name">expression</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">evaluator</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">OnMismatch</span>&gt;</span>NEUTRAL<span class="hljs-tag">&lt;/<span class="hljs-name">OnMismatch</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">OnMatch</span>&gt;</span>DENY<span class="hljs-tag">&lt;/<span class="hljs-name">OnMatch</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">filter</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">encoder</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">pattern</span>&gt;</span>%-4relative [%thread] %-5level %logger - %msg%n<span class="hljs-tag">&lt;/<span class="hljs-name">pattern</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">encoder</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">appender</span>&gt;</span>

  <span class="hljs-tag">&lt;<span class="hljs-name">root</span> <span class="hljs-attr">level</span>=<span class="hljs-string">&quot;DEBUG&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">appender-ref</span> <span class="hljs-attr">ref</span>=<span class="hljs-string">&quot;STDOUT&quot;</span> /&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">root</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">configuration</span>&gt;</span>
</code></pre>
<p>&#x901A;&#x8FC7; <em>evaluatorWithMatcher.xml</em> &#x8FD0;&#x884C;&#xFF1A;</p>
<pre><code class="lang-bash">java chapters.filters.FilterEvents src/main/java/chapters/filters/evaluatorWithMatcher.xml
</code></pre>
<p>&#x5C06;&#x4F1A;&#x5F97;&#x5230;&#xFF1A;</p>
<pre><code class="lang-java"><span class="hljs-number">260</span>  [main] INFO  chapters.filters.FilterEvents - logging statement <span class="hljs-number">0</span>
<span class="hljs-number">264</span>  [main] INFO  chapters.filters.FilterEvents - logging statement <span class="hljs-number">2</span>
<span class="hljs-number">264</span>  [main] INFO  chapters.filters.FilterEvents - logging statement <span class="hljs-number">4</span>
<span class="hljs-number">266</span>  [main] ERROR chapters.filters.FilterEvents - billing statement <span class="hljs-number">6</span>
<span class="hljs-number">266</span>  [main] INFO  chapters.filters.FilterEvents - logging statement <span class="hljs-number">8</span>
</code></pre>
<p>&#x5982;&#x679C;&#x4F60;&#x60F3;&#x5B9A;&#x4E49;&#x5176;&#x5B83;&#x7684; matcher&#xFF0C;&#x53EF;&#x4EE5;&#x7EE7;&#x7EED;&#x589E;&#x52A0; <code>&lt;matcher&gt;</code> &#x5143;&#x7D20;&#x3002;</p>
<h2 id="turbofilters">TurboFilters</h2>
<p><code>TurboFilter</code> &#x5BF9;&#x8C61;&#x90FD;&#x7EE7;&#x627F; <a href="https://logback.qos.ch/xref/ch/qos/logback/classic/turbo/TurboFilter.html" target="_blank"><code>TurboFilter</code></a> &#x62BD;&#x8C61;&#x7C7B;&#x3002;&#x5BF9;&#x4E8E; regular &#x8FC7;&#x6EE4;&#x5668;&#xFF0C;&#x5B83;&#x4EEC;&#x4F7F;&#x7528;&#x4E09;&#x5143;&#x903B;&#x8F91;&#x6765;&#x8FD4;&#x56DE;&#x5BF9;&#x65E5;&#x5FD7;&#x4E8B;&#x4EF6;&#x7684;&#x8BC4;&#x4F30;&#x3002;</p>
<p>&#x603B;&#x4E4B;&#xFF0C;&#x5B83;&#x4EEC;&#x8DDF;&#x4E4B;&#x524D;&#x63D0;&#x5230;&#x7684;&#x8FC7;&#x6EE4;&#x5DE5;&#x4F5C;&#x539F;&#x7406;&#x5DEE;&#x4E0D;&#x591A;&#x3002;&#x4E3B;&#x8981;&#x7684;&#x4E0D;&#x540C;&#x70B9;&#x5728;&#x4E8E; <code>Filter</code> &#x4E0E; <code>TurboFilter</code> &#x5BF9;&#x8C61;&#x3002;</p>
<p><code>TurboFilter</code> &#x5BF9;&#x8C61;&#x88AB;&#x7ED1;&#x5B9A;&#x521A;&#x5728; logger &#x4E0A;&#x4E0B;&#x6587;&#x4E2D;&#x3002;&#x56E0;&#x6B64;&#xFF0C;&#x5728;&#x4F7F;&#x7528;&#x7ED9;&#x5B9A;&#x7684; appender &#x4EE5;&#x53CA;&#x6BCF;&#x6B21;&#x53D1;&#x51FA;&#x7684;&#x65E5;&#x5FD7;&#x8BF7;&#x6C42;&#x90FD;&#x4F1A;&#x8C03;&#x7528; <code>TurboFilter</code> &#x5BF9;&#x8C61;&#x3002;&#x56E0;&#x6B64;&#xFF0C;turbo &#x8FC7;&#x6EE4;&#x5668;&#x53EF;&#x4EE5;&#x4E3A;&#x65E5;&#x5FD7;&#x4E8B;&#x4EF6;&#x63D0;&#x4F9B;&#x9AD8;&#x6027;&#x80FD;&#x7684;&#x8FC7;&#x6EE4;&#xFF0C;&#x5373;&#x4F7F;&#x662F;&#x5728;&#x4E8B;&#x4EF6;&#x88AB;&#x521B;&#x5EFA;&#x4E4B;&#x524D;&#x3002;</p>
<h3 id="&#x5B9E;&#x73B0;&#x81EA;&#x5DF1;&#x7684;-turbofilter">&#x5B9E;&#x73B0;&#x81EA;&#x5DF1;&#x7684; TurboFilter</h3>
<p>&#x60F3;&#x8981;&#x521B;&#x5EFA;&#x81EA;&#x5DF1;&#x7684; <code>TurboFilter</code> &#x7EC4;&#x4EF6;&#xFF0C;&#x53EA;&#x9700;&#x8981;&#x7EE7;&#x627F; <code>TurboFilter</code> &#x8FD9;&#x4E2A;&#x62BD;&#x8C61;&#x7C7B;&#x5C31;&#x53EF;&#x4EE5;&#x4E86;&#x3002;&#x8DDF;&#x4E4B;&#x524D;&#x7684;&#x4E00;&#x6837;&#xFF0C;&#x60F3;&#x8981;&#x5B9E;&#x73B0;&#x5B9A;&#x5236;&#x7684;&#x8FC7;&#x6EE4;&#x5668;&#x5BF9;&#x8C61;&#xFF0C;&#x5F00;&#x53D1;&#x81EA;&#x5B9A;&#x4E49;&#x7684; <code>TurboFilter</code>&#xFF0C;&#x53EA;&#x9700;&#x8981;&#x5B9E;&#x73B0; <code>decide()</code> &#x65B9;&#x6CD5;&#x5C31;&#x53EF;&#x4EE5;&#x4E86;&#x3002;&#x4E0B;&#x4E00;&#x4E2A;&#x4F8B;&#x5B50;&#xFF0C;&#x6211;&#x4EEC;&#x4F1A;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x7A0D;&#x5FAE;&#x590D;&#x6742;&#x4E00;&#x70B9;&#x7684;&#x8FC7;&#x6EE4;&#x5668;&#xFF1A;</p>
<blockquote>
<p>  Example: <em>SampleTurboFilter.java</em></p>
</blockquote>
<pre><code class="lang-java"><span class="hljs-keyword">package</span> chapters.filters;

<span class="hljs-keyword">import</span> org.slf4j.Marker;
<span class="hljs-keyword">import</span> org.slf4j.MarkerFactory;

<span class="hljs-keyword">import</span> ch.qos.logback.classic.Level;
<span class="hljs-keyword">import</span> ch.qos.logback.classic.Logger;
<span class="hljs-keyword">import</span> ch.qos.logback.classic.turbo.TurboFilter;
<span class="hljs-keyword">import</span> ch.qos.logback.core.spi.FilterReply;

<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">SampleTurboFilter</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">TurboFilter</span> </span>{

  String marker;
  Marker markerToAccept;

  <span class="hljs-meta">@Override</span>
  <span class="hljs-function"><span class="hljs-keyword">public</span> FilterReply <span class="hljs-title">decide</span><span class="hljs-params">(Marker marker, Logger logger, Level level,
      String format, Object[] params, Throwable t)</span> </span>{

    <span class="hljs-keyword">if</span> (!isStarted()) {
      <span class="hljs-keyword">return</span> FilterReply.NEUTRAL;
    }

    <span class="hljs-keyword">if</span> ((markerToAccept.equals(marker))) {
      <span class="hljs-keyword">return</span> FilterReply.ACCEPT;
    } <span class="hljs-keyword">else</span> {
      <span class="hljs-keyword">return</span> FilterReply.NEUTRAL;
    }
  }

  <span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">getMarker</span><span class="hljs-params">()</span> </span>{
    <span class="hljs-keyword">return</span> marker;
  }

  <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">setMarker</span><span class="hljs-params">(String markerStr)</span> </span>{
    <span class="hljs-keyword">this</span>.marker = markerStr;
  }

  <span class="hljs-meta">@Override</span>
  <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">start</span><span class="hljs-params">()</span> </span>{
    <span class="hljs-keyword">if</span> (marker != <span class="hljs-keyword">null</span> &amp;&amp; marker.trim().length() &gt; <span class="hljs-number">0</span>) {
      markerToAccept = MarkerFactory.getMarker(marker);
      <span class="hljs-keyword">super</span>.start(); 
    }
  }
}
</code></pre>
<p><code>TurboFilter</code> &#x63A5;&#x53D7;&#x4E00;&#x4E2A;&#x6307;&#x5B9A;&#x7684; marker&#xFF0C;&#x5982;&#x679C; marker &#x6CA1;&#x6709;&#x88AB;&#x627E;&#x5230;&#xFF0C;&#x90A3;&#x4E48;&#x8FC7;&#x6EE4;&#x5668;&#x4F1A;&#x5C06;&#x65E5;&#x5FD7;&#x4E8B;&#x4EF6;&#x4F20;&#x9012;&#x7ED9;&#x8FC7;&#x6EE4;&#x5668;&#x94FE;&#x4E2D;&#x7684;&#x4E0B;&#x4E00;&#x4E2A;&#x8FC7;&#x6EE4;&#x5668;&#x3002;</p>
<p>&#x4E3A;&#x4E86;&#x66F4;&#x52A0;&#x7075;&#x6D3B;&#xFF0C;&#x5141;&#x8BB8;&#x5728;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x6307;&#x5B9A; marker &#x7528;&#x4E8E;&#x68C0;&#x6D4B;&#xFF0C;&#x56E0;&#x6B64;&#x53EF;&#x4EE5;&#x4F7F;&#x7528; get  &#x548C; set &#x65B9;&#x6CD5;&#x3002;&#x6211;&#x4EEC;&#x8FD8;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x5B9E;&#x73B0; <code>start()</code> &#x65B9;&#x6CD5;&#x6765;&#x68C0;&#x67E5;&#x5728;&#x914D;&#x7F6E;&#x8FC7;&#x7A0B;&#x4E2D;&#xFF0C;&#x6307;&#x5B9A;&#x7684;&#x9009;&#x9879;&#x662F;&#x5426;&#x6EE1;&#x8DB3;&#x3002;</p>
<p>&#x4E0B;&#x9762;&#x7684;&#x914D;&#x7F6E;&#x5145;&#x5206;&#x5229;&#x7528;&#x4E86;&#x6211;&#x4EEC;&#x65B0;&#x521B;&#x5EFA;&#x7684; <code>TurboFilter</code>&#x3002;</p>
<blockquote>
<p>Example: <em>sampleTurboFilterConfig.xml</em> </p>
</blockquote>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">configuration</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">turboFilter</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;chapters.filters.SampleTurboFilter&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">Marker</span>&gt;</span>sample<span class="hljs-tag">&lt;/<span class="hljs-name">Marker</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">turboFilter</span>&gt;</span>

  <span class="hljs-tag">&lt;<span class="hljs-name">appender</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;STDOUT&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;ch.qos.logback.core.ConsoleAppender&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">encoder</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">pattern</span>&gt;</span>
        %-4relative [%thread] %-5level %logger - %msg%n
      <span class="hljs-tag">&lt;/<span class="hljs-name">pattern</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">encoder</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">appender</span>&gt;</span>

  <span class="hljs-tag">&lt;<span class="hljs-name">root</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">appender-ref</span> <span class="hljs-attr">ref</span>=<span class="hljs-string">&quot;STDOUT&quot;</span> /&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">root</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">configuration</span>&gt;</span>
</code></pre>
<p>loback-classic &#x9644;&#x5E26;&#x4E86;&#x51E0;&#x4E2A; <code>TurboFilter</code> &#x7C7B;&#x53EF;&#x4EE5;&#x5F00;&#x7BB1;&#x5373;&#x7528;&#x3002;<a href="https://logback.qos.ch/xref/ch/qos/logback/classic/turbo/MDCFilter.html" target="_blank"><code>MDCFilter</code></a> &#x7528;&#x6765;&#x68C0;&#x67E5;&#x7ED9;&#x5B9A;&#x7684;&#x503C;&#x5728; MDC &#x4E2D;&#x662F;&#x5426;&#x5B58;&#x5728;&#x3002;<a href="https://logback.qos.ch/apidocs/ch/qos/logback/classic/turbo/DynamicThresholdFilter.html" target="_blank"><code>DynamicThresholdFilter</code></a> &#x6839;&#x636E; MDC key/level &#x76F8;&#x5173;&#x7684;&#x9600;&#x503C;&#x6765;&#x8FDB;&#x884C;&#x8FC7;&#x6EE4;&#x3002;<a href="https://logback.qos.ch/xref/ch/qos/logback/classic/turbo/MarkerFilter.html" target="_blank"><code>MarkerFilter</code></a> &#x7528;&#x6765;&#x68C0;&#x67E5;&#x65E5;&#x5FD7;&#x8BF7;&#x6C42;&#x4E2D;&#x6307;&#x5B9A;&#x7684; marker &#x662F;&#x5426;&#x5B58;&#x5728;&#x3002;</p>
<p>&#x4E0B;&#x9762;&#x7684;&#x4F8B;&#x5B50;&#x4F7F;&#x7528;&#x4E86; <code>MDCFilter</code> &#x4E0E; <code>MarkerFilter</code>&#x3002;</p>
<blockquote>
<p>Example: <em>turboFilters.xml</em></p>
</blockquote>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">configuration</span>&gt;</span>

  <span class="hljs-tag">&lt;<span class="hljs-name">turboFilter</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;ch.qos.logback.classic.turbo.MDCFilter&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">MDCKey</span>&gt;</span>username<span class="hljs-tag">&lt;/<span class="hljs-name">MDCKey</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">Value</span>&gt;</span>sebastien<span class="hljs-tag">&lt;/<span class="hljs-name">Value</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">OnMatch</span>&gt;</span>ACCEPT<span class="hljs-tag">&lt;/<span class="hljs-name">OnMatch</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">turboFilter</span>&gt;</span>

  <span class="hljs-tag">&lt;<span class="hljs-name">turboFilter</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;ch.qos.logback.classic.turbo.MarkerFilter&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">Marker</span>&gt;</span>billing<span class="hljs-tag">&lt;/<span class="hljs-name">Marker</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">OnMatch</span>&gt;</span>DENY<span class="hljs-tag">&lt;/<span class="hljs-name">OnMatch</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">turboFilter</span>&gt;</span>

  <span class="hljs-tag">&lt;<span class="hljs-name">appender</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;console&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;ch.qos.logback.core.ConsoleAppender&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">encoder</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">pattern</span>&gt;</span>%date [%thread] %-5level %logger - %msg%n<span class="hljs-tag">&lt;/<span class="hljs-name">pattern</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">encoder</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">appender</span>&gt;</span>

  <span class="hljs-tag">&lt;<span class="hljs-name">root</span> <span class="hljs-attr">level</span>=<span class="hljs-string">&quot;INFO&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">appender-ref</span> <span class="hljs-attr">ref</span>=<span class="hljs-string">&quot;console&quot;</span> /&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">root</span>&gt;</span>  
<span class="hljs-tag">&lt;/<span class="hljs-name">configuration</span>&gt;</span>
</code></pre>
<p>&#x6267;&#x884C;&#x4EE5;&#x4E0B;&#x547D;&#x4EE4;&#xFF1A;</p>
<pre><code class="lang-bash">java chapters.filters.FilterEvents src/main/java/chapters/filters/turboFilters.xml
</code></pre>
<p>&#x5728;&#x4E4B;&#x524D;&#x6211;&#x4EEC;&#x770B;&#x5230; <a href="https://logback.qos.ch/xref/chapters/filters/FilterEvents.html" target="_blank"><code>FilterEvents</code></a> &#x8F93;&#x51FA;&#x4E86; 10 &#x6761;&#x65E5;&#x5FD7;&#x8BF7;&#x6C42;&#xFF0C;&#x7F16;&#x53F7; 0 &#x5230; 9&#x3002;&#x9664;&#x4E86;&#x7B2C; 3 &#x6761;&#x4E0E;&#x7B2C; 6 &#x6761;&#xFF0C;&#x6240;&#x6709;&#x7684;&#x8BF7;&#x6C42;&#x90FD;&#x662F; INFO &#x7EA7;&#x522B;&#x7684;&#xFF0C;&#x4E0E; root logger &#x7684;&#x7EA7;&#x522B;&#x4E00;&#x81F4;&#x3002;&#x7B2C; 3 &#x6761;&#x65E5;&#x5FD7;&#x8BF7;&#x6C42;&#x662F; <code>DEBUG</code> &#x7EA7;&#x522B;&#x7684;&#xFF0C;&#x5728;&#x6709;&#x6548;&#x7EA7;&#x522B;&#x4E4B;&#x4E0B;&#x3002;&#x4F46;&#x662F;&#xFF0C;&#x56E0;&#x4E3A; MDC &#x7684; key &quot;username&quot; &#x5728;&#x7B2C;&#x4E09;&#x6761;&#x8BF7;&#x6C42;&#x4E4B;&#x524D;&#x8BBE;&#x7F6E;&#x4E3A; &quot;sebastien&quot;&#xFF0C;&#x4E4B;&#x540E;&#x624D;&#x88AB;&#x79FB;&#x9664;&#xFF0C;&#x6240;&#x4EE5; <code>MDCFilter</code> &#x63A5;&#x53D7;&#x8FD9;&#x6761;&#x8BF7;&#x6C42; (&#x4EC5;&#x4EC5;&#x53EA;&#x6709;&#x8FD9;&#x6761;&#x8BF7;&#x6C42;)&#x3002;&#x7B2C; 6 &#x6761;&#x8BF7;&#x6C42;&#x7684;&#x7EA7;&#x522B;&#x4E3A; <code>ERROR</code>&#xFF0C;&#x88AB;&#x6807;&#x8BB0;&#x4E3A; &quot;billing&quot;&#x3002;&#x56E0;&#x6B64;&#xFF0C;&#x5B83;&#x4F1A;&#x88AB; <code>MarkerFilter</code> (&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x4E2D;&#x7B2C;&#x4E8C;&#x4E2A; turbo &#x8FC7;&#x6EE4;&#x5668;) &#x62D2;&#x7EDD;&#x3002;</p>
<p>&#x56E0;&#x6B64;&#xFF0C;<code>FilterEvents</code> &#x901A;&#x8FC7; <em>turboFilters.xml</em> &#x8F93;&#x51FA;&#x7684;&#x4FE1;&#x606F;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-java"><span class="hljs-number">2018</span>-<span class="hljs-number">08</span>-<span class="hljs-number">20</span> <span class="hljs-number">23</span>:<span class="hljs-number">19</span>:<span class="hljs-number">28</span>,<span class="hljs-number">807</span> [main] INFO  chapters.filters.FilterEvents - logging statement <span class="hljs-number">0</span>
<span class="hljs-number">2018</span>-<span class="hljs-number">08</span>-<span class="hljs-number">20</span> <span class="hljs-number">23</span>:<span class="hljs-number">19</span>:<span class="hljs-number">28</span>,<span class="hljs-number">810</span> [main] INFO  chapters.filters.FilterEvents - logging statement <span class="hljs-number">1</span>
<span class="hljs-number">2018</span>-<span class="hljs-number">08</span>-<span class="hljs-number">20</span> <span class="hljs-number">23</span>:<span class="hljs-number">19</span>:<span class="hljs-number">28</span>,<span class="hljs-number">810</span> [main] INFO  chapters.filters.FilterEvents - logging statement <span class="hljs-number">2</span>
<span class="hljs-number">2018</span>-<span class="hljs-number">08</span>-<span class="hljs-number">20</span> <span class="hljs-number">23</span>:<span class="hljs-number">19</span>:<span class="hljs-number">28</span>,<span class="hljs-number">810</span> [main] DEBUG chapters.filters.FilterEvents - logging statement <span class="hljs-number">3</span>
<span class="hljs-number">2018</span>-<span class="hljs-number">08</span>-<span class="hljs-number">20</span> <span class="hljs-number">23</span>:<span class="hljs-number">19</span>:<span class="hljs-number">28</span>,<span class="hljs-number">810</span> [main] INFO  chapters.filters.FilterEvents - logging statement <span class="hljs-number">4</span>
<span class="hljs-number">2018</span>-<span class="hljs-number">08</span>-<span class="hljs-number">20</span> <span class="hljs-number">23</span>:<span class="hljs-number">19</span>:<span class="hljs-number">28</span>,<span class="hljs-number">810</span> [main] INFO  chapters.filters.FilterEvents - logging statement <span class="hljs-number">5</span>
<span class="hljs-number">2018</span>-<span class="hljs-number">08</span>-<span class="hljs-number">20</span> <span class="hljs-number">23</span>:<span class="hljs-number">19</span>:<span class="hljs-number">28</span>,<span class="hljs-number">810</span> [main] INFO  chapters.filters.FilterEvents - logging statement <span class="hljs-number">7</span>
<span class="hljs-number">2018</span>-<span class="hljs-number">08</span>-<span class="hljs-number">20</span> <span class="hljs-number">23</span>:<span class="hljs-number">19</span>:<span class="hljs-number">28</span>,<span class="hljs-number">811</span> [main] INFO  chapters.filters.FilterEvents - logging statement <span class="hljs-number">8</span>
<span class="hljs-number">2018</span>-<span class="hljs-number">08</span>-<span class="hljs-number">20</span> <span class="hljs-number">23</span>:<span class="hljs-number">19</span>:<span class="hljs-number">28</span>,<span class="hljs-number">811</span> [main] INFO  chapters.filters.FilterEvents - logging statement <span class="hljs-number">9</span>
</code></pre>
<p>&#x53EF;&#x4EE5;&#x770B;&#x5230;&#xFF0C;&#x7B2C; 3 &#x6761;&#x65E5;&#x5FD7;&#x8BF7;&#x6C42;&#xFF0C;&#x672C;&#x6765;&#x4E0D;&#x5E94;&#x8BE5;&#x88AB;&#x5C55;&#x793A;&#x51FA;&#x6765;&#xFF0C;&#x56E0;&#x4E3A;&#x6211;&#x4EEC;&#x4EC5;&#x4EC5;&#x53EA;&#x5173;&#x6CE8; <em>INFO</em> &#x7EA7;&#x522B;&#x7684;&#x8BF7;&#x6C42;&#xFF0C;&#x4F46;&#x662F;&#x5B83;&#x5339;&#x914D;&#x4E86;&#x7B2C;&#x4E00;&#x4E2A; <code>TurboFilter</code>&#xFF0C;&#x6240;&#x4EE5;&#x88AB;&#x63A5;&#x53D7;&#x4E86;&#x3002;</p>
<p>&#x7B2C; 6 &#x6761;&#x65E5;&#x5FD7;&#x8BF7;&#x6C42;&#xFF0C;&#x5B83;&#x662F; <em>ERROR</em> &#x7EA7;&#x522B;&#x7684;&#x65E5;&#x5FD7;&#xFF0C;&#x5E94;&#x8BE5;&#x88AB;&#x663E;&#x793A;&#x3002;&#x4F46;&#x662F;&#x56E0;&#x4E3A;&#x6EE1;&#x8DB3;&#x7B2C;&#x4E8C;&#x4E2A; <code>TurboFilter</code>&#xFF0C;&#x5B83;&#x7684; <code>OnMatch</code> &#x8BBE;&#x7F6E;&#x4E3A; <em>DENY</em>&#xFF0C;&#x6240;&#x4EE5;&#x7B2C; 6 &#x6761;&#x8BF7;&#x6C42;&#x4E0D;&#x4F1A;&#x88AB;&#x5C55;&#x793A;&#x3002;</p>
<h3 id="duplicatemessagefilter">DuplicateMessageFilter</h3>
<p><code>DuplicateMessageFilter</code> &#x53EF;&#x4EE5;&#x62FF;&#x51FA;&#x6765;&#x5355;&#x72EC;&#x9610;&#x8FF0;&#x3002;&#x8FD9;&#x4E2A;&#x8FC7;&#x6EE4;&#x5668;&#x68C0;&#x6D4B;&#x91CD;&#x590D;&#x7684;&#x6D88;&#x606F;&#xFF0C;&#x5728;&#x91CD;&#x590D;&#x4E86;&#x4E00;&#x5B9A;&#x6B21;&#x6570;&#x4E4B;&#x540E;&#xFF0C;&#x4E22;&#x5F03;&#x6389;&#x91CD;&#x590D;&#x7684;&#x6D88;&#x606F;&#x3002;</p>
<p>&#x8FD9;&#x4E2A;&#x8FC7;&#x6EE4;&#x5668;&#x4F7F;&#x7528;&#x5B57;&#x7B26;&#x4E32;&#x662F;&#x5426;&#x76F8;&#x7B49;&#x6765;&#x68C0;&#x67E5;&#x662F;&#x5426;&#x91CD;&#x590D;&#x3002;&#x4E0D;&#x4F1A;&#x68C0;&#x67E5;&#x975E;&#x5E38;&#x76F8;&#x4F3C;&#xFF0C;&#x4EC5;&#x4EC5;&#x53EA;&#x5DEE;&#x51E0;&#x4E2A;&#x5B57;&#x7B26;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#x3002;&#x4F8B;&#x5982;&#xFF1A;</p>
<pre><code class="lang-java">logger.debug(<span class="hljs-string">&quot;Hello &quot;</span>+name0);
logger.debug(<span class="hljs-string">&quot;Hello &quot;</span>+name1);
</code></pre>
<p>&#x5982;&#x679C; <code>name0</code> &#x4E0E; <code>name1</code> &#x6709;&#x4E0D;&#x540C;&#x7684;&#x503C;&#xFF0C;&#x90A3;&#x4E48;&#x4E24;&#x4E2A; &quot;Hello&quot; &#x6D88;&#x606F;&#x4F1A;&#x88AB;&#x8BA4;&#x4E3A;&#x4E0D;&#x76F8;&#x5173;&#x3002;&#x6839;&#x636E;&#x7528;&#x6237;&#x7684;&#x9700;&#x8981;&#xFF0C;&#x5C06;&#x4F1A;&#x53EF;&#x80FD;&#x4F1A;&#x652F;&#x6301;&#x76F8;&#x4F3C;&#x5B57;&#x7B26;&#x4E32;&#x7684;&#x68C0;&#x67E5;&#xFF0C;&#x9650;&#x5236;&#x76F8;&#x4F3C;&#x5B57;&#x7B26;&#x4E32;&#x7684;&#x91CD;&#x590D;&#xFF0C;&#x800C;&#x4E0D;&#x662F;&#x5B8C;&#x5168;&#x76F8;&#x540C;&#x7684;&#x3002;</p>
<p>&#x4F46;&#x662F;&#x5728;&#x53C2;&#x6570;&#x5316;&#x65E5;&#x5FD7;&#x8BF7;&#x6C42;&#x4E2D;&#xFF0C;&#x53EA;&#x8003;&#x8651;&#x539F;&#x59CB;&#x6D88;&#x606F;&#x3002;&#x4F8B;&#x5982;&#xFF0C;&#x4E0B;&#x9762;&#x4E24;&#x6761;&#x65E5;&#x5FD7;&#x8BF7;&#x6C42;&#xFF0C;&#x539F;&#x59CB;&#x6D88;&#x606F;&#x4E3A; &quot;Hello {}&quot;&#xFF0C;&#x5B83;&#x4EEC;&#x88AB;&#x8BA4;&#x4E3A;&#x662F;&#x60F3;&#x76F8;&#x7B49;&#x7684;&#xFF0C;&#x56E0;&#x6B64;&#x88AB;&#x8BA4;&#x4E3A;&#x662F;&#x91CD;&#x590D;&#x51FA;&#x73B0;&#x3002;</p>
<pre><code class="lang-javascript">logger.debug(<span class="hljs-string">&quot;Hello {}.&quot;</span>, name0);
logger.debug(<span class="hljs-string">&quot;Hello {}.&quot;</span>, name1);
</code></pre>
<p>&#x53EF;&#x4EE5;&#x901A;&#x8FC7; <code>AllowedRepetitions</code> &#x5C5E;&#x6027;&#x6765;&#x6307;&#x5B9A;&#x5141;&#x8BB8;&#x91CD;&#x590D;&#x7684;&#x6B21;&#x6570;&#x3002;&#x5982;&#x679C;&#x8FD9;&#x4E2A;&#x5C5E;&#x6027;&#x88AB;&#x8BBE;&#x7F6E;&#x4E3A; 1&#xFF0C;&#x90A3;&#x4E48;&#x7B2C;&#x4E8C;&#x6761;&#x4EE5;&#x53CA;&#x540E;&#x7EED;&#x7684;&#x65E5;&#x5FD7;&#x6D88;&#x606F;&#x90FD;&#x4F1A;&#x88AB;&#x4E22;&#x5F03;&#x6389;&#x3002;&#x7C7B;&#x4F3C;&#x7684;&#xFF0C;&#x5982;&#x679C;&#x88AB;&#x8BBE;&#x7F6E;&#x4E3A; 2&#xFF0C;&#x90A3;&#x4E48;&#x7B2C;&#x4E09;&#x6761;&#x53CA;&#x540E;&#x7EED;&#x7684;&#x65E5;&#x5FD7;&#x6D88;&#x606F;&#x4F1A;&#x88AB;&#x4E22;&#x5F03;&#x6389;&#x3002;&#x8FD9;&#x4E2A;&#x503C;&#x9ED8;&#x8BA4;&#x8BBE;&#x7F6E;&#x4E3A; 5&#x3002;</p>
<p>&#x4E3A;&#x4E86;&#x68C0;&#x6D4B;&#x91CD;&#x590D;&#xFF0C;&#x8FC7;&#x6EE4;&#x5668;&#x9700;&#x8981;&#x5728;&#x5185;&#x90E8;&#x7684;&#x7F13;&#x5B58;&#x4E2D;&#x4FDD;&#x7559;&#x5BF9;&#x65E7;&#x6D88;&#x606F;&#x7684;&#x5F15;&#x7528;&#x3002;&#x901A;&#x8FC7; <code>CacheSize</code> &#x6765;&#x63A7;&#x5236;&#x7F13;&#x5B58;&#x7684;&#x5927;&#x5C0F;&#x3002;&#x9ED8;&#x8BA4;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x8FD9;&#x4E2A;&#x503C;&#x4E3A; 100&#x3002;</p>
<blockquote>
<p>  Example: <em>duplicateMessage.xml</em></p>
</blockquote>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">configuration</span>&gt;</span>

  <span class="hljs-tag">&lt;<span class="hljs-name">turboFilter</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;ch.qos.logback.classic.turbo.DuplicateMessageFilter&quot;</span>/&gt;</span>

  <span class="hljs-tag">&lt;<span class="hljs-name">appender</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;console&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;ch.qos.logback.core.ConsoleAppender&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">encoder</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">pattern</span>&gt;</span>%date [%thread] %-5level %logger - %msg%n<span class="hljs-tag">&lt;/<span class="hljs-name">pattern</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">encoder</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">appender</span>&gt;</span>

  <span class="hljs-tag">&lt;<span class="hljs-name">root</span> <span class="hljs-attr">level</span>=<span class="hljs-string">&quot;INFO&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">appender-ref</span> <span class="hljs-attr">ref</span>=<span class="hljs-string">&quot;console&quot;</span> /&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">root</span>&gt;</span>  
<span class="hljs-tag">&lt;/<span class="hljs-name">configuration</span>&gt;</span>
</code></pre>
<p><code>FilterEvents</code> &#x901A;&#x8FC7; <code>duplicateMessage.xml</code> &#x914D;&#x7F6E;&#x540E;&#x8F93;&#x51FA;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-java"><span class="hljs-number">2018</span>-<span class="hljs-number">08</span>-<span class="hljs-number">21</span> <span class="hljs-number">09</span>:<span class="hljs-number">09</span>:<span class="hljs-number">22</span>,<span class="hljs-number">036</span> [main] INFO  chapters.filters.FilterEvents - logging statement <span class="hljs-number">0</span>
<span class="hljs-number">2018</span>-<span class="hljs-number">08</span>-<span class="hljs-number">21</span> <span class="hljs-number">09</span>:<span class="hljs-number">09</span>:<span class="hljs-number">22</span>,<span class="hljs-number">041</span> [main] INFO  chapters.filters.FilterEvents - logging statement <span class="hljs-number">1</span>
<span class="hljs-number">2018</span>-<span class="hljs-number">08</span>-<span class="hljs-number">21</span> <span class="hljs-number">09</span>:<span class="hljs-number">09</span>:<span class="hljs-number">22</span>,<span class="hljs-number">041</span> [main] INFO  chapters.filters.FilterEvents - logging statement <span class="hljs-number">2</span>
<span class="hljs-number">2018</span>-<span class="hljs-number">08</span>-<span class="hljs-number">21</span> <span class="hljs-number">09</span>:<span class="hljs-number">09</span>:<span class="hljs-number">22</span>,<span class="hljs-number">041</span> [main] INFO  chapters.filters.FilterEvents - logging statement <span class="hljs-number">4</span>
<span class="hljs-number">2018</span>-<span class="hljs-number">08</span>-<span class="hljs-number">21</span> <span class="hljs-number">09</span>:<span class="hljs-number">09</span>:<span class="hljs-number">22</span>,<span class="hljs-number">041</span> [main] INFO  chapters.filters.FilterEvents - logging statement <span class="hljs-number">5</span>
<span class="hljs-number">2018</span>-<span class="hljs-number">08</span>-<span class="hljs-number">21</span> <span class="hljs-number">09</span>:<span class="hljs-number">09</span>:<span class="hljs-number">22</span>,<span class="hljs-number">050</span> [main] ERROR chapters.filters.FilterEvents - billing statement <span class="hljs-number">6</span>
</code></pre>
<p>&quot;logging statement 0&quot; &#x662F;&#x6D88;&#x606F; &quot;logging statement {}&quot;j &#x7B2C;&#x4E00;&#x6B21;&#x51FA;&#x73B0;&#x3002;&quot;logging statement 1&quot; &#x662F;&#x7B2C;&#x4E00;&#x6B21;&#x91CD;&#x590D;&#x3002;&quot;logging statement 2&quot; &#x662F;&#x7B2C;&#x4E8C;&#x6B21;&#x91CD;&#x590D;&#x3002;&#x6709;&#x8DA3;&#x7684;&#x662F;&#xFF0C;&#x867D;&#x7136; &quot;logging statement 3&quot; &#x7684;&#x7EA7;&#x522B;&#x4E3A; <em>DEBUG</em>&#xFF0C;&#x4E3A;&#x7B2C;&#x4E09;&#x6B21;&#x91CD;&#x590D;&#x3002;&#x4F46;&#x662F;&#x6839;&#x636E;<a href="https://github.com/Volong/logback-chinese-manual/blob/master/02%E7%AC%AC%E4%BA%8C%E7%AB%A0%EF%BC%9A%E6%9E%B6%E6%9E%84.md#%E6%96%B9%E6%B3%95%E6%89%93%E5%8D%B0%E4%BB%A5%E5%8F%8A%E5%9F%BA%E6%9C%AC%E9%80%89%E6%8B%A9%E8%A7%84%E5%88%99" target="_blank">&#x65B9;&#x6CD5;&#x6253;&#x5370;&#x4EE5;&#x53CA;&#x57FA;&#x672C;&#x9009;&#x62E9;&#x89C4;&#x5219;</a>&#xFF0C;&#x5B83;&#x88AB;&#x4E22;&#x5F03;&#x4E86;&#x3002;&#x8FD9;&#x4E5F;&#x8BF4;&#x660E;&#x4E86; turbo &#x8FC7;&#x6EE4;&#x5668;&#x4F1A;&#x5728;&#x5176;&#x5B83;&#x8FC7;&#x6EE4;&#x5668;&#x4E4B;&#x524D;&#x8C03;&#x7528;&#xFF0C;&#x5305;&#x62EC;&#x5728;&#x57FA;&#x672C;&#x9009;&#x62E9;&#x89C4;&#x5219;&#x4E4B;&#x524D;&#x3002;&#x56E0;&#x6B64; <code>DuplicateMessageFilter</code> &#x8BA4;&#x4E3A; &quot;logging statement 3&quot; &#x662F;&#x7B2C;&#x4E09;&#x6B21;&#x91CD;&#x590D;&#xFF0C;&#x800C;&#x4E0D;&#x4F1A;&#x7BA1;&#x5B83;&#x662F;&#x5426;&#x4F1A;&#x5728;&#x4E4B;&#x540E;&#x8FC7;&#x6EE4;&#x5668;&#x94FE;&#x7684;&#x5904;&#x7406;&#x4E2D;&#x88AB;&#x4E22;&#x5F03;&#x6389;&#x3002;&quot;logging statement 4&quot; &#x662F;&#x7B2C;&#x56DB;&#x6B21;&#x91CD;&#x590D;&#x3002;&quot;logging statement 5&quot; &#x662F;&#x7B2C;&#x4E94;&#x6B21;&#x3002;&#x56E0;&#x6B64;&#x9ED8;&#x8BA4;&#x7684;&#x91CD;&#x590D;&#x6B21;&#x6570;&#x662F; 5&#xFF0C;&#x6240;&#x4EE5;&#x4E4B;&#x540E;&#x7684;&#x8BED;&#x53E5;&#x90FD;&#x4F1A;&#x88AB;&#x4E22;&#x5F03;&#x6389;&#x3002;(&#x6CE8;&#xFF1A;&#x6307;&#x7684;&#x662F; &quot;logging statement {}&quot;)&#x3002;</p>
<h1 id="&#x5728;-logback-access-&#x4E2D;">&#x5728; logback-access &#x4E2D;</h1>
<p>logback-access &#x63D0;&#x4F9B;&#x4E86; logback-classic &#x63D0;&#x4F9B;&#x7684;&#x5927;&#x90E8;&#x5206;&#x529F;&#x80FD;&#x3002;&#x7279;&#x522B;&#x5730;&#xFF0C;<code>Filter</code> &#x5BF9;&#x8C61;&#x540C;&#x6837;&#x662F;&#x6709;&#x6548;&#x7684;&#xFF0C;&#x5E76;&#x4E14;&#x4EE5;&#x540C;&#x6837;&#x7684;&#x65B9;&#x5F0F;&#x5DE5;&#x4F5C;&#xFF0C;&#x5C31;&#x50CF; logback-classic &#x7684;&#x526F;&#x672C;&#x4E00;&#x6837;&#xFF0C;&#x4F46;&#x662F;&#x6709;&#x4E00;&#x4E2A;&#x663E;&#x8457;&#x7684;&#x533A;&#x522B;&#x3002;logback-access &#x8FC7;&#x6EE4;&#x5668;&#x5BF9; <a href="https://logback.qos.ch/xref/ch/qos/logback/access/spi/AccessEvent.html" target="_blank"><code>AccessEvent</code></a> &#x5B9E;&#x4F8B;&#x8D77;&#x4F5C;&#x7528;&#xFF0C;&#x800C;&#x4E0D;&#x662F; <code>LoggingEvent</code> &#x5B9E;&#x4F8B;&#x3002;&#x76EE;&#x524D;&#xFF0C;logback-access &#x53EA;&#x63D0;&#x4F9B;&#x4E86;&#x4EE5;&#x4E0B;&#x6709;&#x9650;&#x7684;&#x8FC7;&#x6EE4;&#x5668;&#x3002;&#x5982;&#x679C;&#x4F60;&#x60F3;&#x5EFA;&#x8BAE;&#x6DFB;&#x52A0;&#x989D;&#x5916;&#x7684;&#x8FC7;&#x6EE4;&#x5668;&#xFF0C;&#x8BF7;&#x901A;&#x8FC7; logback-dev &#x90AE;&#x4EF6;&#x5217;&#x8868;&#x8FDB;&#x884C;&#x8054;&#x7CFB;&#x3002;</p>
<h2 id="countingfilter">CountingFilter</h2>
<p>&#x5728; <a href="https://logback.qos.ch/manual/xref/ch/qos/logback/access/filter/CountingFilter.html" target="_blank"><code>CountingFilter</code></a> &#x7C7B;&#x7684;&#x5E2E;&#x52A9;&#x4E0B;&#xFF0C;logback-access &#x53EF;&#x4EE5;&#x63D0;&#x4F9B;&#x5BF9;&#x670D;&#x52A1;&#x5668;&#x8BBF;&#x95EE;&#x6570;&#x636E;&#x7684;&#x7EDF;&#x8BA1;&#x3002;&#x5728;&#x521D;&#x59CB;&#x5316;&#x7684;&#x6B7B;&#x540E;&#xFF0C;<code>CountingFilter</code> &#x5C06;&#x81EA;&#x5DF1;&#x4F5C;&#x4E3A;&#x4E00;&#x4E2A; MBean &#x6CE8;&#x518C;&#x5230;&#x5E73;&#x53F0;&#x7684; JMX &#x670D;&#x52A1;&#x4E0A;&#x3002;&#x4F60;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x8F6E;&#x8BE2; MBean &#x6765;&#x8FDB;&#x884C;&#x6570;&#x636E;&#x7EDF;&#x8BA1;&#x3002;&#x4F8B;&#x5982;&#xFF0C;&#x5E73;&#x5747;&#x6BCF;&#x5206;&#x949F;&#xFF0C;&#x6BCF;&#x5C0F;&#x65F6;&#xFF0C;&#x6BCF;&#x5929;&#xFF0C;&#x6BCF;&#x5468;&#xFF0C;&#x6216;&#x8005;&#x6BCF;&#x6708;&#x3002;&#x5176;&#x5B83;&#x7684;&#x7EDF;&#x8BA1;&#xFF0C;&#x4F8B;&#x5982;&#x5468;&#x8BA1;&#xFF0C;&#x5929;&#x8BA1;&#xFF0C;&#x5C0F;&#x65F6;&#x8BA1;&#xFF0C;&#x6708;&#x8BA1;&#x6216;&#x8005;&#x603B;&#x8BA1;&#x4E5F;&#x662F;&#x53EF;&#x4EE5;&#x83B7;&#x53D6;&#x7684;&#x3002;</p>
<p>&#x4E0B;&#x9762;&#x7684; <em>logback-access.xml</em> &#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x58F0;&#x660E;&#x4E86;&#x4E00;&#x4E2A; <code>CountingFilter</code>&#x3002;</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">configuration</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">statusListener</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;ch.qos.logback.core.status.OnConsoleStatusListener&quot;</span> /&gt;</span>

  <span class="hljs-tag">&lt;<span class="hljs-name">filter</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;ch.qos.logback.access.filter.CountingFilter&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>countingFilter<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">filter</span>&gt;</span>

  <span class="hljs-tag">&lt;<span class="hljs-name">appender</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;STDOUT&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;ch.qos.logback.core.ConsoleAppender&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">encoder</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">pattern</span>&gt;</span>%h %l %u %t \&quot;%r\&quot; %s %b<span class="hljs-tag">&lt;/<span class="hljs-name">pattern</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">encoder</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">appender</span>&gt;</span>

  <span class="hljs-tag">&lt;<span class="hljs-name">appender-ref</span> <span class="hljs-attr">ref</span>=<span class="hljs-string">&quot;STDOUT&quot;</span> /&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">configuration</span>&gt;</span>
</code></pre>
<p>&#x4F60;&#x53EF;&#x4EE5;&#x901A;&#x8FC7; <code>jconsole</code> &#x67E5;&#x770B;&#x6709; <code>CountingFilte</code> &#x5728;&#x4F60;&#x5E73;&#x53F0;&#x7684; JMX &#x670D;&#x52A1;&#x4E0A;&#x7EF4;&#x62A4;&#x7684;&#x5404;&#x79CD;&#x7EDF;&#x8BA1;&#x4FE1;&#x606F;&#x3002;</p>
<p><img src="images/countingFilter.png" alt=""></p>
<h3 id="evaluatorfilter">EvaluatorFilter</h3>
<p><a href="https://logback.qos.ch/xref/ch/qos/logback/core/filter/EvaluatorFilter.html" target="_blank"><code>EvaluatorFilter</code></a> &#x662F;&#x4E00;&#x4E2A;&#x901A;&#x7528;&#x7684;&#x8FC7;&#x6EE4;&#x5668;&#xFF0C;&#x7EF4;&#x62A4;&#x4E86;&#x4E00;&#x4E2A; <code>EventEvaluator</code>&#x3002;&#x987E;&#x540D;&#x601D;&#x4E49;&#xFF0C;<a href="https://logback.qos.ch/xref/ch/qos/logback/core/boolex/EventEvaluator.html" target="_blank"><code>EventEvaluator</code></a> &#x6839;&#x636E;&#x7ED9;&#x5B9A;&#x7684;&#x6807;&#x51C6;&#x5224;&#x65AD;&#x7ED9;&#x5B9A;&#x7684;&#x65E5;&#x5FD7;&#x4E8B;&#x4EF6;&#x662F;&#x5426;&#x6EE1;&#x8DB3;&#xFF0C;<code>EvaluatorFilter</code> &#x5C06;&#x4F1A;&#x6839;&#x636E; match &#x4E0E; mismatch &#x7684;&#x60C5;&#x51B5;&#xFF0C;&#x8FD4;&#x56DE;&#x7531; <code>onMatch</code> &#x6216; <code>onMismatch</code> &#x5C5E;&#x6027;&#x6307;&#x5B9A;&#x7684;&#x503C;&#x3002;<code>EvaluatorFilter</code> &#x5728;&#x4E4B;&#x524D;&#x7684; logback-classic &#x4E2D;&#x5DF2;&#x7ECF;&#x8BA8;&#x8BBA;&#x8FC7;&#x4E86; (<a href="https://github.com/Volong/logback-chinese-manual/blob/master/07%E7%AC%AC%E4%B8%83%E7%AB%A0%EF%BC%9AFilters.md#evaluatorfilter" target="_blank">&#x89C1;&#x4E0A;&#x9762;</a>)&#x3002;&#x73B0;&#x5728;&#x5927;&#x90E8;&#x5206;&#x90FD;&#x662F;&#x5BF9;&#x4E4B;&#x524D;&#x8BA8;&#x8BBA;&#x7684;&#x91CD;&#x590D;&#x3002;</p>
<p>&#x6CE8;&#x610F; <code>EventEvaluator</code> &#x662F;&#x4E00;&#x4E2A;&#x62BD;&#x8C61;&#x7C7B;&#x3002;&#x4F60;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x7EE7;&#x627F; <code>EventEvaluator</code> &#x6765;&#x5B9E;&#x73B0;&#x4F60;&#x81EA;&#x5DF1;&#x7684;&#x8BC4;&#x4F30;&#x903B;&#x8F91;&#x3002;logback-access &#x9644;&#x5E26;&#x4E86;&#x4E00;&#x4E2A;&#x540D;&#x4E3A; <a href="https://logback.qos.ch/xref/ch/qos/logback/access/boolex/JaninoEventEvaluator.html" target="_blank">JaninoEventEvaluator</a> &#x7684;&#x5177;&#x4F53;&#x5B9E;&#x73B0;&#x3002;&#x5B83;&#x53EF;&#x4EE5;&#x63A5;&#x6536;&#x4EFB;&#x610F;&#x7684; Java &#x8868;&#x8FBE;&#x5F0F;&#x4F5C;&#x4E3A;&#x8BC4;&#x4F30;&#x6807;&#x51C6;&#x3002;&#x6211;&#x4EEC;&#x628A;&#x8FD9;&#x79CD; Java &#x4EE3;&#x7801;&#x5757;&#x79F0;&#x4E3A; &quot;<em>&#x8BC4;&#x4F30;&#x8868;&#x8FBE;&#x5F0F;</em>&quot;&#x3002;&#x8BC4;&#x4F30;&#x8868;&#x8FBE;&#x5F0F;&#x5728;&#x4E8B;&#x4EF6;&#x8FC7;&#x6EE4;&#x4E2D;&#x6709;&#x8F83;&#x5927;&#x7684;&#x7075;&#x6D3B;&#x6027;&#x3002;<code>JaninoEventEvaluator</code> &#x9700;&#x8981; <a href="http://docs.codehaus.org/display/JANINO/Home" target="_blank">Janino &#x7C7B;&#x5E93;</a>&#x3002;&#x8BF7;&#x67E5;&#x770B;<a href="https://logback.qos.ch/setup.html#janino" target="_blank">&#x76F8;&#x5E94;&#x7684;&#x6587;&#x6863;</a>&#x8FDB;&#x884C;&#x8BBE;&#x7F6E;&#x3002;</p>
<p>&#x8BC4;&#x4F30;&#x8868;&#x8FBE;&#x5F0F;&#x5728;&#x89E3;&#x6790;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x7684;&#x8FC7;&#x7A0B;&#x4E2D;&#x88AB;&#x52A8;&#x6001;&#x7F16;&#x8BD1;&#x3002;&#x4F5C;&#x4E3A;&#x7528;&#x6237;&#xFF0C;&#x4F60;&#x4E0D;&#x9700;&#x8981;&#x77E5;&#x9053;&#x5B9E;&#x9645;&#x7684;&#x7EC6;&#x8282;&#x3002;&#x4F46;&#x662F;&#xFF0C;&#x4F60;&#x9700;&#x8981;&#x4FDD;&#x8BC1; Java &#x8868;&#x8FBE;&#x5F0F;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x5E03;&#x5C14;&#x503C;&#xFF0C;&#x80FD;&#x591F;&#x8BA1;&#x7B97;&#x4E3A; true &#x6216;&#x8005; false&#x3002;</p>
<p>&#x8BC4;&#x4F30;&#x8868;&#x8FBE;&#x5F0F;&#x53EF;&#x4EE5;&#x5BF9;&#x5F53;&#x524D;&#x8BBF;&#x95EE;&#x7684;&#x4E8B;&#x4EF6;&#x8FDB;&#x884C;&#x8BC4;&#x4F30;&#x3002;logback-access &#x4F1A;&#x81EA;&#x52A8;&#x5BFC;&#x51FA;&#x5F53;&#x524D; <code>AccessEvent</code> &#x5B9E;&#x4F8B;&#x5230;&#x53D8;&#x91CF; <strong>event</strong> &#x4E0B;&#x3002;&#x4F60;&#x53EF;&#x4EE5;&#x901A;&#x8FC7; <code>event</code> &#x53D8;&#x91CF;&#x8BFB;&#x53D6; HTTP &#x8BF7;&#x6C42;&#x4E2D;&#x4EE5;&#x53CA; HTTP &#x54CD;&#x5E94;&#x4E2D;&#x7684;&#x5404;&#x79CD;&#x6570;&#x636E;&#x3002;&#x67E5;&#x770B; <a href="https://logback.qos.ch/xref/ch/qos/logback/access/spi/AccessEvent.html" target="_blank">AccessEvent &#x7C7B;&#x7684;&#x6E90;&#x7801;</a>&#x6765;&#x67E5;&#x770B;&#x5177;&#x4F53;&#x7684;&#x5217;&#x8868;&#x3002;</p>
<p>&#x4E0B;&#x4E2A;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x57FA;&#x4E8E; HTTP &#x54CD;&#x5E94;&#x7801; <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.5" target="_blank">404 (Not Found)</a> &#x6765;&#x8FDB;&#x884C;&#x8FC7;&#x6EE4;&#x3002;&#x6BCF;&#x4E00;&#x4E2A; 404 &#x7684;&#x8BF7;&#x6C42;&#x90FD;&#x4F1A;&#x5728;&#x63A7;&#x5236;&#x53F0;&#x6253;&#x5370;&#x51FA;&#x6765;&#x3002;</p>
<blockquote>
<p>  Example: <em>accessEventEvaluator.xml</em></p>
</blockquote>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">configuration</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">statusListener</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;ch.qos.logback.core.status.OnConsoleStatusListener&quot;</span> /&gt;</span>

  <span class="hljs-tag">&lt;<span class="hljs-name">appender</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;STDOUT&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;ch.qos.logback.core.ConsoleAppender&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">filter</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;ch.qos.logback.core.filter.EvaluatorFilter&quot;</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">evaluator</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">expression</span>&gt;</span>event.getStatusCode() == 404<span class="hljs-tag">&lt;/<span class="hljs-name">expression</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">evaluator</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">onMismatch</span>&gt;</span>DENY<span class="hljs-tag">&lt;/<span class="hljs-name">onMismatch</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">filter</span>&gt;</span>
   <span class="hljs-tag">&lt;<span class="hljs-name">encoder</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">pattern</span>&gt;</span>%h %l %u %t %r %s %b<span class="hljs-tag">&lt;/<span class="hljs-name">pattern</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">encoder</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">appender</span>&gt;</span>

  <span class="hljs-tag">&lt;<span class="hljs-name">appender-ref</span> <span class="hljs-attr">ref</span>=<span class="hljs-string">&quot;STDOUT&quot;</span> /&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">configuration</span>&gt;</span>
</code></pre>
<p>&#x4E0B;&#x9762;&#x7684;&#x4F8B;&#x5B50;&#xFF0C;&#x6253;&#x5370; 404 &#x9519;&#x8BEF;&#xFF0C;&#x4F46;&#x662F;&#x6392;&#x9664;&#x4E86;&#x8BF7;&#x6C42; CSS &#x6587;&#x4EF6;&#x7684;&#x8BF7;&#x6C42;&#x3002;</p>
<blockquote>
<p>  Example: <em>accessEventEvaluator2.xml</em></p>
</blockquote>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">configuration</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">statusListener</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;ch.qos.logback.core.status.OnConsoleStatusListener&quot;</span> /&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">appender</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;STDOUT&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;ch.qos.logback.core.ConsoleAppender&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">filter</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;ch.qos.logback.core.filter.EvaluatorFilter&quot;</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">evaluator</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;Eval404&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">expression</span>&gt;</span>
         (event.getStatusCode() == 404)
           &amp;amp;&amp;amp;  <span class="hljs-comment">&lt;!-- &amp; &#x7B26;&#x53F7;&#x9700;&#x8981;&#x88AB;&#x8F6C;&#x4E49; --&gt;</span>
         !(event.getRequestURI().contains(&quot;.css&quot;))
        <span class="hljs-tag">&lt;/<span class="hljs-name">expression</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">evaluator</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">onMismatch</span>&gt;</span>DENY<span class="hljs-tag">&lt;/<span class="hljs-name">onMismatch</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">filter</span>&gt;</span>

   <span class="hljs-tag">&lt;<span class="hljs-name">encoder</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">pattern</span>&gt;</span>%h %l %u %t %r %s %b<span class="hljs-tag">&lt;/<span class="hljs-name">pattern</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">encoder</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">appender</span>&gt;</span>

  <span class="hljs-tag">&lt;<span class="hljs-name">appender-ref</span> <span class="hljs-attr">ref</span>=<span class="hljs-string">&quot;STDOUT&quot;</span> /&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">configuration</span>&gt;</span>
</code></pre>



                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="06第六章Layouts.html" class="navigation navigation-prev " aria-label="Previous page: 第六章：Layouts">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="08第八章MDC.html" class="navigation navigation-next " aria-label="Next page: 第八章：MDC">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"第七章：Filters","level":"1.8","depth":1,"next":{"title":"第八章：MDC","level":"1.9","depth":1,"path":"08第八章MDC.md","ref":"08第八章MDC.md","articles":[]},"previous":{"title":"第六章：Layouts","level":"1.7","depth":1,"path":"06第六章Layouts.md","ref":"06第六章Layouts.md","articles":[]},"dir":"ltr"},"config":{"plugins":["add-js-css","myseo"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"add-js-css":{"js":["./lib/site.js"]},"myseo":{"description":"logback中文网包含了logback中文文档，最新资讯，应用案例等。logback 继承自 log4j，它建立在有十年工业经验的日志系统之上。它比其它所有的日志系统更快并且更小，包含了许多独特并且有用的特性。","keywords":"logback中文文档, logback api文档, logback log4j,springboot logback,logback日志类型","titlePrefix":"logback中文网|"},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","keywords":"","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"logback中文手册","gitbook":"*","description":""},"file":{"path":"07第七章Filters.md","mtime":"2019-02-12T05:09:40.000Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-02-24T03:19:05.191Z"},"basePath":".","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="gitbook/gitbook.js"></script>
    <script src="gitbook/theme.js"></script>
    
        
        <script src="gitbook/gitbook-plugin-add-js-css/fda70cfc36440304bb976a11f47eb151-site.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

